Pass arguments to osascript via shell function in OS X Mountain Lion

applescriptbashosascriptosx-mountain-lion

The answer in How to open a new Firefox window with URL argument is broken in Mac OSX Mountain Lion (10.8.2). I can't comment on that answer or question, so I had to create a new question.

It fails like this:

$ firefox-window http://www.yahoo.com
dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/osascript) is code signed with entitlements

The new window opens successfully, but it's empty (i.e. the environment variable passed to the AppleScript in the bash function is ignored).

Is there an alternate way to pass variables to applescript from the commandline? (perhaps not using bash?)

References

"A sandboxed app can’t use AppleScript to communicate with another app on your Mac, unless the developer specifically requests (and receives) an entitlement to do just that."

So I'm guessing that this restriction prevents the technique used above, i.e. a bash script can't wrap an applescript that talks to firefox.

workaround #1

Call it directly instead of using the shell variable ($1). For example, this works:

$ osascript ~/bin/firefox-window.scpt "http://www.yahoo.com"

Firefox opens a new window pointed at yahoo.

Best Answer

osascript -e 'tell application "Firefox"' -e 'open location "http://example.com/"' -e 'end tell'

That should do it, in a new tab, not a new window, if that's okay.

Related Question