Skip navigation.
 
mlRe: Command Line Arguments
FROM : Ondra Cada
DATE : Mon Apr 11 16:30:15 2005

Jason,

On 11.4.2005, at 16:09, Jason Whitehorn wrote:

> I am a newbie when it comes to Cocoa programming, and am currently
> trying to figure out how command line arguments are passed to my
> program.


Actually you are not :))

> I have a program that I am trying to associate with a specific file
> type, and when I double click an associated file in Finder, I want my
> program to launch and do something with the file.


This is done for you by the application framework.

Presumed your app is a document-based one, you don't do anything: the
file is automatically opened and you get it through the appopriate
NSDocument API (see NSDocument, or -- for starters -- just create an
NSDocument subclass in Xcode and see the method skeletons generated for
you).

Otherwise, you are informed through NSApplication delegate methods.
Check the NSApplication documenation.

> I thought that I was suppose to use NSProcessInfo to accomplish this
> goal, but all the "arguments" method accomplishes is getting me the
> same "-psn_0_100401153" string that I was able to get from directly
> accessing argv within main.


Incidentally, *if* you ever need to access the CLI arguments, do use
NSProcessInfo (or, in simpler cases, plain old NSUserDefaults), *not*
directly main.
---
Ondra Čada
OCSoftware:    <email_removed>              http://www.ocs.cz
private        <email_removed>            http://www.ocs.cz/oc

Related mailsAuthorDate
mlCommand Line Arguments Jason Whitehorn Apr 11, 16:09
mlRe: Command Line Arguments Ondra Cada Apr 11, 16:30
mlRe: Command Line Arguments Dan Saul Apr 11, 18:16
mlRe: Command Line Arguments Finlay Dobbie Apr 11, 23:13