Figuring out the current default browser

I do switch default browsers and I have scripts referring to my browser. Is there a nice way to figure out the app name of the current default browser on macOS with AS? Thanks!

This should help.

Running a shell script from AppleScript

https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/CallCommandLineUtilities.html

Shell Script to Get Default Browser

https://discussions.apple.com/thread/251602703

Thank you for the shell script. I’ll let KeyboardMaestro save it in a var and get the name from there :wink:

As the author noted, there is no user friendly way!

So, I’ve switched back from Firefox to Safari. Man, it works as intended. When Viscosity is connected, it does launch Safari, the kill switch does quit Safari, my BTT Steam button does quit a bunch of apps, including Safari. No more changing scripts from Firefox to Safari. Thanks!

btw some characters in a browser name are URL encoded. Like all the spaces in “Safari Technology Preview” Do you know how to decode the string it in the shell script?

There are quite a few ways to do this. The most common options are using shell substitution instructions (e.g. sed, native) or Python 2/3.

Just search for “urldecode command line mac” in your favourite search engine and take your pick for what implementation makes most sense to you.

I am baffled. The last time I’ve used Safari Technology Preview must be in Catalina. So, I’ve downloaded it again today for Big Sur (Yes, it is out today). My global KeyboardMaestro variable theBrowser is still “Safari%20Technology%20Preview”. But the AppleScript launching my apps when my VPN is connected has no problem activating “Safari%20Technology%20Preview”. Dunno what did get smarter, but I remember it failing in Catalina. TLDR It appears I do not need to decode it. Cheers!