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

1

1

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.

Larry Kyrala

Posted 2012-11-05T13:33:54.870

Reputation: 373

Interesting. This is a "security feature" related to Gatekeeper in 10.8 and has been reported already. I'm not sure there's a fix yet. I reworded and generalized your question a little, otherwise it'd be a duplicate of the one you linked to. I hope someone has a workaround for this, then I could also update my answer on the first question. – slhck – 2012-11-05T13:46:54.610

thank you! I saw a couple questions pertaining to the security feature, and I understand what they are trying to prevent by enforcing it this way, but the workarounds so far show applescripts that don't have any variable input. My second guess is to rewrite the function in pure applescript and pass vars in from the command line instead of using env vars, but I'm still working that out. – Larry Kyrala – 2012-11-05T13:54:28.170

Answers

0

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.

Caleb Xu

Posted 2012-11-05T13:33:54.870

Reputation: 1 523