Simple question

I have a script that I use to launch an application with some options. The question revolves around these two statements


do shell script "/Applications/Firefox.app/Contents/MacOS/firefox-bin -ProfileManager &"

return

The statement launches Firefox’s profile manager and then after I select a profile Firefox launches. The problem is that the Applescript just sits there running and never executes the “return” to stop.

Any thoughts on this?

Model: Mac Pro
AppleScript: 2.1.2
Browser: Firefox 4.0b7
Operating System: Mac OS X (10.6)

Found the answer after a few minutes of Googling


do shell script "/Applications/Firefox.app/Contents/MacOS/firefox-bin -ProfileManager  > /dev/null 2>&1 &"

A little bit simpler code without backgrounding and piping stderr and stdout of your application.

do shell script "open /Applications/Firefox.app/ --args  -ProfileManager"

That is simple.

I just figured out the syntax for the longer version by reviewing the bash documentation. Question,

In the FF documentation they always use this

/Applications/Firefox.app/Contents/MacOS/firefox-bin -ProfileManager

the bash I added after that assigns stdout and stderr to null (as I understand it).

So what exactly does your short form do and why does it not need to point to the firefox-bin?

do shell script “open /Applications/Firefox.app/ --args -ProfileManager”

You could also just point me to a reference.

Thanks

Open will open the bundle.app and will look for the info.plist file. here it finds the executable in this file (on my machine its firefox-bin) and will launch it just like the finder does. The only advantage is that people with tweaked or other versions of firefox (where the file is named different) your script doesn’t work. I’ve also seen apps with more than one file in MacOS folder then again open will always opens the same version as the finder. I’m also suprised that FF don’t do this in their documentation

What does the

–args

do?

It’s probably not in the documentation because ‘open’ is an OS X specific command that isn’t available on other platforms and the writers may not have been aware of it. It’s basically the same as double-clicking a file in the Finder.

To be quite safe in situations where the user may have put Firefox in a different place, the best way to do it is:
do shell script “open -b org.mozilla.firefox --args -ProfileManager”

–args passes the remaining arguments to Firefox rather than trying to use them as arguments of ‘open’ itself. For more info, check the man page for open.

Thanks

Thanks gannet, I didn’t know this either.

Regarding man pages. They are easier to read in something like Preview. I created a file called

.profile

in the root of my user account. In the file I have this

pman()
{
man -t “${1}” | open -f -a /Applications/Preview.app/
}

Now when I want to read/find/go back in a man page I simply enter this in the terminal

pman bash

and I have the bash or other info opened in Preview.

Her’s an alternative:

set theResult to text returned of (display dialog "Command to man:" default answer "")
do shell script ("man -t " & (quoted form of theResult) & " | open -f -a /Applications/Preview.app") 

I like that :slight_smile:

Why doesn’t this work?

man -t ls | open -f -b com.apple.Preview

Good question, although -f does say “opens the results in the default text editor” so I guess we shouldn’t complain. It’s just odd that -fa works while -fb doesn’t.
Note that -a doesn’t need the full path to the app, you can just put “-a Preview”.