Howto start an Application from command line / terminal.app
June 30th, 2007 at 10:48I guess everyone knows howto start appliations from OSX Gui. Personally i prefer the application Namely, as it is quick and small. Many OSX Users are using Quicksilver for that purpose, but lets talk today about the idea of starting application from command line (called Terminal.app) in OSX.
I am mentioning that way, as i already had the situation that i was sitting in front of my Mac, waiting for the end of the horrible rotating wheel/ball. Thats the point where to want to access your mac from remote, kill some aplications from commandline, maybe relaunch some other .app’s or just shuting the Mac down.
Lets start:
Open application from command line:
- Run Terminal.app ( can be found in /Application/Utilities/ )
- Now lets see all running processes on your Mac, by entering: ps xau
- You should see a big list of processes sorted by User, PID, %CPU, % MEM and a bunch of additional informations. I use that command normaly to get an overviewof the status of all running processes.
- Now we want tostart a new Application or Process. In this example we want to start iTunes, as i assume eyerone has that installed.
- Enter: open -a iTunes
- As result iTunes should open up.
- Done
Ok, i guess that was really easy, as supposed to be. Some additional notes and examples.
Open application with spaces in the app name from command line:
If you want to open up an Application containing Spaces in the name you have to deal with Terminal ways to work with Spaces. In this small example we want to open Disk Utility.
- Open Terminal.app
- Entering: open -a Disk\ Utility.app would be the default notation for Applications containing a Space in its name. In this special case that should not work, as DU is not directly located in /Applications. Unfortunally it is located in /Applications/Utilities.
- kongo:~ fidel$ open -a Disk\ Utility.app/
2007-06-30 10:31:41.282 open[482] Couldn’t launch application: Disk Utility.app/
- kongo:~ fidel$ open -a Disk\ Utility.app/
- So enter: open -a /Applications/Utilities/Disk\ Utility.app/
- kongo:~ fidel$ open -a /Applications/Utilities/Disk\ Utility.app/
kongo:~ fidel$
- kongo:~ fidel$ open -a /Applications/Utilities/Disk\ Utility.app/
- Done.
Start TextEditor to edit a text file from command line:
Last example. You are on command line and want to edit a text file. Well vi is a nice command-line-based text-editor, but not everyone really likes to use it. So now we want to start our favorite GUI Text editor and a random text-file on our harddisk. I have created a demo .txt-file on my Desktop called foobar.txt
As Text-Editors i can recommend:
- Smultron
- TextWrangler
For sure, a quick search an Versiontracker.com or Macupdate.com will bring up several other applications. but now lets continue:
- Open Terminal.app
- Enter: open -a Smultron /absolute/path/t/your/textfile
- kongo:~ fidel$ open -a Smultron /Users/fidel/Desktop/foobar.txt
kongo:~ fidel$
- kongo:~ fidel$ open -a Smultron /Users/fidel/Desktop/foobar.txt
So i think that was everything you need to handle that topic. Enjoy it
Best regards
fidel
Tags: 10.4, cli, commandline, howto start apps from cli, open -a, open ., open application, open from, open from terminal, terminal



January 6th, 2009 at 21:54
Thanks – have you figured how to open and edit a textfile that is restricted to root only?
For example: open -a /Applications/TextEdit.app /etc/apache2/httpd.conf
Will open launch the app and open the httpd.conf file. But it’s not editable.
sudo open -a …
does not work. Do you have an idea aside from changing permission prior to editing, then reverting access control post edit?
January 6th, 2009 at 22:15
not really, i’m sorry.
Only hint i can give you maybe is mentioning the app Pseudo X – which is somehow like a run-as-root droplet if i remeber correctly. Totally other attempt, but i guess one you might think about.
If you find another solution please lemme know =)
Best regards
fidel