Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Command line options for Safari

I have a script that opens a Safari window by doing essentially the following:

open -a safari http://www.apple.com

According to the man page for open, I can add more args to this that would get picked up by Safari, as follows. Of course the man page for open can't indicate what such args might be or even if Safari pays any attention to them:

open -a safari http://www.apple.com --args arg1 arg2 ...

Are there any such args one can usefully pass to Safari in this way? Specifically, I'd like the command to be able to control the size of the window that is opened, perhaps as follows:

open -a safari http://www.apple.com --args h=300 w=400

Thanks.

Mac Mini Core 2 Duo 1.8GHz, Mac OS X (10.6.6)

Posted on Jan 19, 2011 2:53 PM

Reply
1 reply

Jan 20, 2011 6:25 AM in response to ClothEars-2

While I'm no Terminal expert, I believe you might be interested in using osascript. You can check its man page by entering *man osascript* at the Terminal prompt. Also, a Google search for osascript should yield some good returns.

In short, entering *osascript -e* at the Terminal prompt, followed by a valid AppleScript command executes the script action. More than one argument can be used at a time by adding another -e, followed by a new AppleScript command.

The example below causes Safari to open apple.com, with the window resized to your specifications. Copy the entire piece of code, paste it at the Terminal prompt, and press Return:

*osascript -e 'tell application "Safari" to open location "http://www.apple.com"' -e 'tell application "Safari" to set bounds of front window to {10, 60, 400, 300}'*

Good luck, hope this helps.

Command line options for Safari

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.