Created
September 21, 2023 21:55
-
-
Save hbisneto/e6807d6fa234260bfac672b62175d6d7 to your computer and use it in GitHub Desktop.
Swift code used to get applications list running in a macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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