Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift on macOS: open Chrome with a URL as parameter

Tags:

macos

swift

I'd like to open Chrome with a specific URL from my macOS app.

I'm trying it like this, but unfortunately it doesn't work. Chrome is opened, but not with the given URL String.

let configuration = NSWorkspace.OpenConfiguration()
configuration.arguments = [url.absoluteString]
let appUrl = URL(fileURLWithPath: "/Applications/Google Chrome.app")
NSWorkspace.shared.openApplication(at: appUrl,
    configuration: configuration,
    completionHandler: nil)

open() does not help me in this case, as I don't want to open the standard browser.

Help is highly appreciated!

like image 410
Chris Jung Avatar asked Nov 05 '25 05:11

Chris Jung


1 Answers

I solved it.

NSWorkspace.shared.open([url],
    withApplicationAt: URL(fileURLWithPath: "/Applications/Google Chrome.app"),
    configuration: configuration)

did the trick

like image 184
Chris Jung Avatar answered Nov 07 '25 07:11

Chris Jung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!