how to launch applications with command line options?

Greetings folks, I'm sure there's a simple solution to this but I'm just not finding it elsewhere...

...I'd really like to have an icon on my desktop or in my dock to launch an application with specific command line options (in my case, Opera). Isn't there some way to do this without having to create an Applescript or a shell script?

I'd like to just have an icon that launches Opera and doesn't result in Terminal windows opening up.

Mac Pro, Mac OS X (10.5.7)

Posted on May 18, 2009 1:11 PM

Reply
13 replies

May 18, 2009 1:19 PM in response to zentraedidotnet

zentraedidotnet wrote:
Greetings folks, I'm sure there's a simple solution to this but I'm just not finding it elsewhere...

...I'd really like to have an icon on my desktop or in my dock to launch an application with specific command line options (in my case, Opera). Isn't there some way to do this without having to create an Applescript or a shell script?


I'd like to just have an icon that launches Opera and doesn't result in Terminal windows opening up.

make workflow in Automator consisting of a single action "run shell script" and put whatever you need inside. save it as an application. launching it will do what you want without opening a terminal window.

May 18, 2009 6:43 PM in response to zentraedidotnet

zentraedidotnet wrote:
Interesting, that's pretty much what I did, only I wrote an Applescript and saved it as an application. Unfortunately the specific machine I need this for is running Panther (but we have plenty of Leopard machines too). If I create the application using Automator on a Leopard machine, is the resulting application portable to a Panther machine?

probably not but I haven't used panther in years so i can't be sure. i suggest you do it directly on the panther machine. using applescript will work too.

May 19, 2009 2:42 PM in response to zentraedidotnet

zentraedidotnet wrote:
Can you point me at an example of how to launch an application using command line options in Applescript that does not open a Terminal window?

Thanks!
zentraedidotnet wrote:
Can you point me at an example of how to launch an application using command line options in Applescript that does not open a Terminal window?

Thanks!

could you explain why you necessarily want to do it using apple script? you don't appear very familiar with it in which case using automator is certainly easier.
in general to run a terminal command inside apple script you
use "do shell script" construct.

put

do shell script "your terminal command here"


in your apple script.
For example


do shell script "open -a /Applications/TextEdit.app '/Volumes/Macintosh HD/foo.txt'"


will open foo.txt in TextEdit

May 19, 2009 2:59 PM in response to V.K.

Okay, I think where we're missing each other are two points:

1) I'm pretty sure Automator doesn't exist in Panther, but it doesn't matter because...

2) You can't use "open -a" to run an application with commandline arguments

I'm not trying to tell Mac OS to "open file Y in application X". I'm trying to tell Mac OS to "open application X with the following command line options -yz".

For example, you can't do this...

do shell script "open -a /Applications/Opera.app/Contents/MacOS/Opera -k"

...or this:

do shell script "open -a '/Applications/Opera.app/Contents/MacOS/Opera -k'"

I understand Applescript, and I understand shell scripting. What I am looking for is a way to create a launcher/icon/package/whatever that, when you click on it, runs a command with command line switches (like, for example, -k).

Does that make more sense?

May 20, 2009 5:58 AM in response to zentraedidotnet

zentraedidotnet wrote:
Okay, I think where we're missing each other are two points:

1) I'm pretty sure Automator doesn't exist in Panther, but it doesn't matter because...

2) You can't use "open -a" to run an application with commandline arguments

I'm not trying to tell Mac OS to "open file Y in application X". I'm trying to tell Mac OS to "open application X with the following command line options -yz".

For example, you can't do this...

do shell script "open -a /Applications/Opera.app/Contents/MacOS/Opera -k"

...or this:

do shell script "open -a '/Applications/Opera.app/Contents/MacOS/Opera -k'"


those were just examples! the particular command i used "open -a blah blah" is quite irrelevant. you put whatever terminal command you need there as I said.
it will look something like

do shell script "your terminal command with switches"

if you can run the command with switches from terminal you can put it in the above script.

May 20, 2009 6:25 AM in response to V.K.

Oh, sorry, I thought you were suggesting using the "open" command to resolve my issue with the Terminal window appearing or staying open. I don't really want to involve Terminal at all (don't want to confuse silly users or present them a window to type who knows what into).

Simply calling my application with a "do shell script" seems to always open a Terminal window, which is something I tried before posting this question. Is there some way to write the shell script that I'm missing to keep Terminal from launching?

It seems like Platypus should resolve my question, but I do find it odd that one has to get so involved in Mac OS X simply to launch something with an option. I hate to say it, but it's so easy in Windows to just right click on a shortcut icon and add an option...

May 20, 2009 8:05 AM in response to zentraedidotnet

zentraedidotnet wrote:
Oh, sorry, I thought you were suggesting using the "open" command to resolve my issue with the Terminal window appearing or staying open. I don't really want to involve Terminal at all (don't want to confuse silly users or present them a window to type who knows what into).

Simply calling my application with a "do shell script" seems to always open a Terminal window, which is something I tried before posting this question. Is there some way to write the shell script that I'm missing to keep Terminal from launching?

that really depends on the exact command you are using. normally no terminal window is opened when apple script executes "do shell script". I'm guessing something in the particular terminal command you are using makes this happen. can't say more without seeing the exact details.
It seems like Platypus should resolve my question, but I do find it odd that one has to get so involved in Mac OS X simply to launch something with an option. I hate to say it, but it's so easy in Windows to just right click on a shortcut icon and add an option...

May 20, 2009 1:36 PM in response to V.K.

Dude, thanks so much for your patience and your help. I don't know what I was doing differently before when I messed with this because we reinstalled the machine at one point, but whatever I had differently in my previous Applescript, now it works perfectly!

Thanks for the encouragement. Now I have a happy little old G4 running as a single-purpose web kiosk, and since the Applescript can be saved as an Application Package, I was able to make it a "login item" for the dummy user that is automatically logged in when the machine boots, which is great!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

how to launch applications with command line options?

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