launchbrowser, but choose specific application?

Weston Jones's icon

Hello! 2 questions I'm hoping someone can answer..

1) Can the launchbrowser command be used in conjunction with any other code to choose which application to use besides the system default? I want to open some URL's in Safari, and others in Chrome.

2) Can max quit an application in OS X?

Thanks!

Source Audio's icon

using shell and osascript, both can be done.

for example to quit Preview.app :
killall Preview
launch location :
osascript -e 'tell application \"Firefox\"' -e 'activate' -e 'open location \"
https://stackoverflow.com\"' -e 'end tell'

Weston Jones's icon

Great that works! I had to install the external shell~ object https://cycling74.com/tools/bernstein-shell/

Thank you.

Weston Jones's icon

One thing I'm having a problem with... If I want to have Firefox in your above example open a HTML file on my computer, not a URL on the web, how would I code that? Putting the pathname in place of the url doesn't work.

Source Audio's icon

osascript -e 'tell application \"Firefox\"' -e 'activate' -e 'open \"/Users/Mac/Desktop/Stack Overflow.html\"' -e 'end tell'

just to make sure : path must be slash based.
like :
/Volumes/Hd-2/example 1.jpg
or
/Documents/Examples/Read me first.html

Weston Jones's icon

works, thank you!

Weston Jones's icon

A problem I'm having now is the killall command isn't quitting Firefox. Works for Safari though...

Source Audio's icon

try typing that in terminal to see error
or enable stderr in shell

either is Firefox run as root, or it is named differently

Weston Jones's icon

Yeah, strange, in Terminal it's giving me the "No matching processes belonging to you were found". I also tried "Firefox.app". No dice. Is there a way to find out the real name?

Source Audio's icon

have a look in Activity Monitor.
It will show exact name as well if it s run as you - user.
If this becomes problematic, one could use osascript to tell app to quit

Weston Jones's icon

kill -9 [pid] works. (the PID is found by checking the application in Activity Monitor). Would still prefer to run by app name, so the patch can work on another machine.

Weston Jones's icon

So should just be "Firefox" right?

Or how to I use osascript to tell app to quit?

Really appreciate the help!

Weston Jones's icon

OK so using all lowercase "killall firefox" works. And it seems you can only use one "Shell" object in max. When I had two, it doesn't work on the second. Wild!

Source Audio's icon

osascript -e 'tell application \"Firefox\"' -e 'quit' -e 'end tell'

Probably the problem is all that Firefox extensions

Weston Jones's icon

yeah oascript way of quitting works much more consistently. Thanks a million.

Source Audio's icon

there is one difference - telling app to quit will bring
dialog asking if one wants to store changes to unsaved document if such is open.
killall quits app not asking anything.

Weston Jones's icon

that is a crucial difference, but at least in my use here, should be fine. Thanks!