1

I don't know why, but why the code below does not have the expected behavior?

let workspace = NSWorkspace.shared if let bundleURL = workspace.urlForApplication(withBundleIdentifier: "com.apple.Safari"){ workspace.open(bundleURL) let conf = NSWorkspace.OpenConfiguration() conf.activates = false conf.hides = true workspace.openApplication(at: bundleURL, configuration: conf){ (app, err) in print(app as Any) print(err as Any) } } 

When I run the code, the Safari application is opening normally, neither “Hides” is working nor “Activates” false is working.

Obs: App Sandboxed: NO | Deployment Target: 11.3 | Xcode: 12.5.1

1 Answer 1

1

You are sort of opening the application twice here:

workspace.open(bundleURL) // first time let conf = NSWorkspace.OpenConfiguration() conf.activates = false conf.hides = true // second time workspace.openApplication(at: bundleURL, configuration: conf){ (app, err) in print(app as Any) print(err as Any) } 

You didn't use the configuration the first time, so it opens it up in the foreground without hiding. And since it has already launched, opening it the second time doesn't do anything.

Just remove workspace.open(bundleURL). It worked for me.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.