image
image

Go Back   macosx.com > Mac Help Forums > Mac OS X System & Mac Software

Reply
 
Thread Tools
  #1  
Old April 19th, 2008, 08:50 PM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
alexworden is on a distinguished road
Starting Applications from the console

Hi,

Can anyone explain how I can start an application from the console. Often I want to view a file from the current directory and I simply want to start an application to view it. I'd also like to be able to start a Finder window in the current directory. I've added the ability to start a console from the Finder, but it would be very useful to do the reverse!

This was easy in Windows, you simply had to know the .exe name of the application. I've tried all sorts on OSX with no success.

In particular, I want to start Safari, Firefox, TextEdit, and Finder..

Thanks for your suggestions!

Alex
Reply With Quote
  #2  
Old April 19th, 2008, 09:08 PM
Registered User
 
Join Date: Jul 2005
Posts: 832
Thanks: 0
Thanked 1 Time in 1 Post
simbalala is on a distinguished road
You need to know the path to the binary executable, What you normally see as an App is really a folder. If you right click on an app you’ll see an option to “Show Package Contents”. You’ll find the executable in the MacOS folder within the package.

For example — TextEdit, the command:

/Applications/TextEdit.app/Contents/MacOS/TextEdit

will launch TextEdit from within Terminal.
Reply With Quote
  #3  
Old April 19th, 2008, 11:02 PM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
alexworden is on a distinguished road
Thanks simbalala,

I can launch Safari with

/Applications/Safari.app/Contents/MacOS/Safari

and it starts OK. I tried creating a symbolic link to it from my ~/bin directory using..

~/bin :ln -s /Applications/Safari.app/Contents/MacOS/Safari
~/bin :ls -l
total 184
lrwxr-xr-x 1 alex staff 46 Apr 19 19:53 Safari -> /Applications/Safari.app/Contents/MacOS/Safari

and sure enough got the link, but when I run it I get..

~/bin :Safari
2008-04-19 19:53:58.092 Safari[6756:10b] No Info.plist file in application bundle or no NSPrincipalClass in the Info.plist file, exiting

Any ideas what's wrong with that? Same thing happens with TextEdit symbolic link.

I'm running Leopard if that's any help.

Another thing that's been bugging me... some applications I can start from the console - that are simple executables - but the window focus doesn't switch to them when they start. I always have to click on them with the mouse. Does anyone know how to make that happen automatically?

Thanks,

Alex
Reply With Quote
  #4  
Old April 20th, 2008, 02:33 PM
Registered User
 
Join Date: Jul 2005
Posts: 832
Thanks: 0
Thanked 1 Time in 1 Post
simbalala is on a distinguished road
I’m not quite sure what you’re wanting to do but if your primary need is invoking TextEdit from the command line have a look at TextWrangler, it’s a free minimized version of BBEdit (which I have). You can install an included command line tool in both TextWrangler and BBEdit.

So you can be in Terminal in any directory and just open a file with this command (I'll use /private/etc/hosts as an example and I've already "cd'd" to /private/etc).

bbedit hosts (for TextWrangler the command is simply 'edit hosts')

This opens hosts in BBEdit and pops BBEdit to the front. You can also save files owned by root by clicking the pencil icon on the far left when it has a red slash though it.

Last edited by simbalala; April 20th, 2008 at 02:44 PM.
Reply With Quote
  #5  
Old April 20th, 2008, 03:27 PM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,505
Thanks: 4
Thanked 15 Times in 14 Posts
Mikuro is on a distinguished road
You can't separate the executable from the application package. Even creating a symbolic link will not work, because once launched, the process will only be aware of the symbolic link's location, not the exectutable's true location. It will then search for necessary files from the package relative to the path of the symbolic link, which obviously will not work.

I guess the easiest way to get equivalent functionality would be to create a shell script which simply launches TextEdit (using the full path), and then put that shell script in ~/bin and call it "TextEdit".

As for opening Finder windows, try this:
Code:
open .
Out of curiosity, how did you go about opening a console from the Finder? Sounds useful.
__________________
Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.5

Useful programs: Privoxy, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc
Reply With Quote
  #6  
Old April 20th, 2008, 03:48 PM
jbarley's Avatar
One more, for the road!
 
Join Date: Jul 2005
Location: An Island called Vancouver
Posts: 369
Thanks: 0
Thanked 2 Times in 2 Posts
jbarley will become famous soon enough
Quote:
Originally Posted by Mikuro View Post
Out of curiosity, how did you go about opening a console from the Finder? Sounds useful.
If by chance it's a Terminal window you want to open,
this little app will do it for you.
Its amazing what a person can find with a google search.

jb.
__________________
ROFL: (Rolling on the floor laughing.) Typically used by people who are too lazy to press the rest of the keys on their keyboard needed to communicate in English.
Reply With Quote
  #7  
Old April 20th, 2008, 04:21 PM
ElDiabloConCaca's Avatar
U.S.D.A. Prime
 
Join Date: Aug 2001
Location: San Antonio, Texas
Posts: 10,354
Thanks: 3
Thanked 119 Times in 109 Posts
ElDiabloConCaca is a jewel in the roughElDiabloConCaca is a jewel in the roughElDiabloConCaca is a jewel in the rough
You can launch .app packages using the Terminal using the shell command "open", like Mikuro says.

For example, you can launch TextEdit from the Terminal by executing the following command:
Code:
open /Applications/TextEdit.app
As far as I can see, applications launched in this fashion are brought into focus when they launch.

You can also provide command-line arguments in this fashion with some applications. For example, if I wished to launch TextEdit from the command line and have TextEdit open a document named "test.txt" on my Desktop (as if I simply double-clicked the document on my Desktop to open it in TextEdit), I could do the following:
Code:
open /Applications/TextEdit.app ~/Desktop/test.txt
...and TextEdit would be launched and brought into focus, with the text document "test.txt" open.
__________________
Power Macintosh G4/500MHz "Yikes!" 10.4.11 Server • 1024MB • 3 x 120GB + 320GB • DVR-111D • 2 x Radeon 7000 PCI • 2 x 17" CRT
MacBook 2.0GHz Core 2 Duo - White 10.5.5 • 2048MB • 80GB • CD-RW/DVD-ROM
iPod Photo 60GB • iPod nano 1GB • AT&T DSL 6Mb/768k
http://www.jeffhoppe.com
Reply With Quote
  #8  
Old April 20th, 2008, 07:46 PM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
alexworden is on a distinguished road
Brilliant! Thank you so much guys! "open" will save me so much time and tedium.

FYI - Open Terminal is the Finder Extension I am already using. Highly recommended!asdf
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 09:06 PM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.