1

I could find a way to open a specific browser (with macOS and Swift):

@IBAction func frx(_ sender: NSButton) {
      NSWorkspace.shared.open(URL(fileURLWithPath: "/Applications/Firefox.app"))
}

Is it possible to give to that Firefox window a new url in a posterior moment and reload the page? (Give the address not when I launch the application but later)

segon
  • 273
  • 1
  • 4
  • 16
  • @Willeke. Thank you. That question is different and does not solve my problem. I am very new to macOS and Swift. As far as I understand, that code seems old as it gives a lot of errors. On the other side, I need to give an address later, not when I launch the application. So, my first problem is to save that window to go back it later. – segon Sep 14 '19 at 15:03
  • Someone posted an answer to a different question which should solve your issue: https://stackoverflow.com/a/41431381/6782707 – Edric Sep 14 '19 at 15:17
  • @Edric. Thank you, but as the other case, that is to open a browser with an url, but what I amb looking for is to change the url of a browser that is already opened. – segon Sep 14 '19 at 19:58

1 Answers1

2
struct Firefox {
    static func open(path: String) {
        let ff_url = NSURL(fileURLWithPath: "/Applications/Firefox.app", isDirectory: true) as URL

        if let www_url = URL(string: path) {
            NSWorkspace.shared.open([www_url], withApplicationAt: ff_url, configuration: NSWorkspace.OpenConfiguration()) { app, error in
                if let error = error {
                    // handle error
                }
                if let _ = app {
                    // handle success
                }
            }
        } else {
            // handle error
        }
    }
}
Vincenso
  • 516
  • 4
  • 8