Skip to content

Instantly share code, notes, and snippets.

@nmggithub
Created July 30, 2025 14:00
Show Gist options
  • Select an option

  • Save nmggithub/770838bf196265cf23ae01d5ff92e436 to your computer and use it in GitHub Desktop.

Select an option

Save nmggithub/770838bf196265cf23ae01d5ff92e436 to your computer and use it in GitHub Desktop.
Launch an application silently on macOS
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