Created
July 30, 2025 14:00
-
-
Save nmggithub/770838bf196265cf23ae01d5ff92e436 to your computer and use it in GitHub Desktop.
Launch an application silently on 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
| var silentConfiguration: NSWorkspace.OpenConfiguration { | |
| let configuration = NSWorkspace.OpenConfiguration() | |
| configuration.perform( | |
| "_setAdditionalLSOpenOptions:", | |
| with: [ | |
| "_kLSOpenOptionUIElementLaunchKey": 1, | |
| "_kLSOpenOptionWaitForApplicationToCheckInKey": 0, | |
| ]) | |
| configuration.activates = false // Don't activate the app | |
| configuration.hides = true // Hide the app on launch | |
| configuration.addsToRecentItems = false // Don't add the app to recents | |
| configuration.createsNewApplicationInstance = true // Try to create a new instance of the app | |
| return configuration | |
| } | |
| try await NSWorkspace.shared.open( | |
| [ | |
| URL(string: "https://www.youtube.com/watch?v=dQw4w9WgXcQ")!, | |
| ], | |
| withApplicationAt: URL(fileURLWithPath: "/Applications/Safari.app"), | |
| configuration: silentConfiguration | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment