Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to startup a Mac OS X application from command line?

Tags:

macos

"open -a" is not the answer wanted, because I want to debug the Mac OS X application automatically. This means it's better if someone can give the command line like [program] [args] format. So ltrace mechanism can make [program] as target for debugging and take [args] as input.

I have tried command line like "/Applications/Microsoft Office 2011/Microsoft PowerPoint.app/Contents/MacOS/Microsoft PowerPoint" /Users/poc.pptx, only Microsoft Point process started but the poc.pptx not opened.

After grepping the Microsoft Point with pptx file opened, it's something like: /Applications/Microsoft Office 2011/Microsoft PowerPoint.app/Contents/MacOS/Microsoft PowerPoint -psn_0_307275, there is no argument "poc.pptx".

I even manually use "gdb /Applications/Microsoft Office 2011/Microsoft PowerPoint.app/Contents/MacOS/Microsoft PowerPoint" and "set args /Users/poc.pptx", and then "r", the target application can not run with the certain file opened.

I am confused about this, so, is there someone can help me to solve this problem?

Thank you!

like image 552
yodaFirst Name Lulu Avatar asked Dec 05 '11 15:12

yodaFirst Name Lulu


4 Answers

Go to file directory and then type

open -a "Microsoft PowerPoint" <filename.ppt>

Here "Microsoft PowerPoint" is the name of power point application, please check name of power point if it is different in your application directory.

This is working perfectly fine on my MAC (OSX 10.8).

We can also give complete path instead of just file name.

    open -a "Microsoft PowerPoint" <ppt file path>

This is also working fine.

like image 83
dadua Avatar answered Nov 10 '22 15:11

dadua


open -b com.microsoft.PowerPoint <filename> seems to work for me to open presentations from the command line.

like image 39
RealCasually Avatar answered Nov 10 '22 13:11

RealCasually


I know this is a old question, but here is my 2ct anyway. I add the applications I want to open through command line in /usr/local/bin as a symlink.

I never run into any problems, but as Ken stated it depends how a application handles arguments.

Example with Visual Studio:

First I check what makes the application start bij executing the file inside the App contents like:

$ /Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron

If that works, then I create the symlink as follows (ln -s <path-to-app> <path-to-symlink>):

$ ln -s /Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron /usr/local/bin/vs

After that I can start up Visual Studio with the current folder loaded as:

~/Development/SomeProject $ vs .

like image 2
Sven van Zoelen Avatar answered Nov 10 '22 15:11

Sven van Zoelen


If PowerPoint is not opening a document passed as a command-line argument, then that's a reflection on how PowerPoint was coded. There's nothing anybody but Microsoft can do about that.

The OS does not normally use that technique to tell applications to open documents. Instead, it passes Apple Events to the application. Cocoa will, by default, accept command-line arguments and treat them similarly to such Apple Events, but apparently PowerPoint is overriding that default behavior.

If you want to debug or trace PowerPoint, I recommend that you do it in two steps. First, launch it without arguments under the debugger or trace program. Then, tell it to open a document. You can do that in the normal way, using the Finder and/or Dock, or you can use open -a .... Such a request to open a document will not launch a second instance of PowerPoint, it will deliver an event to the already-running PowerPoint which you are debugging/tracing. So, the result should be similar to what you seem to want.

like image 1
Ken Thomases Avatar answered Nov 10 '22 15:11

Ken Thomases