Skip to content

Instantly share code, notes, and snippets.

@hbisneto
Created September 21, 2023 21:55
Show Gist options
  • Save hbisneto/e6807d6fa234260bfac672b62175d6d7 to your computer and use it in GitHub Desktop.
Save hbisneto/e6807d6fa234260bfac672b62175d6d7 to your computer and use it in GitHub Desktop.
Swift code used to get applications list running in a macOS
//
// main.swift
// RunningApps
//
// Created by Heitor Bisneto on 21/09/23.
//
import Foundation
import AppKit
// Create a new instance of object NSWorkspace
let Workspace = NSWorkspace.shared
// Get the list of all running applications (including from System)
let Applications = Workspace.runningApplications
// Filter the 'Applications' list removing apps from the System
let EssentialApps = Applications.filter{
$0.activationPolicy == .regular
}
// Show User applications in list
for app in EssentialApps{
print(app.localizedName ?? "")
}
// Show System application in list (includes user applications)
for app in Applications{
print(app.localizedName ?? "")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment