Re: How to pass command line parameters to Cocoa App
Re: How to pass command line parameters to Cocoa App
- Subject: Re: How to pass command line parameters to Cocoa App
- From: Eric Wing <email@hidden>
- Date: Tue, 16 Aug 2011 11:40:13 -0700
On 8/16/11, Abdul Sowayan <email@hidden> wrote:
> Hi folks,
>
> If I launch my app from the command line, I can pass it options like this
> (this would be the argc, argv parameters to main):
>
> ./Foo.app/Contents/MacOS/Foo -ApplePersistenceIgnoreState YES
>
NSArgumentDomain under NSUserDefaults is the usual mechanism that
connects command line arguments like the above to a Cocoa app. You can
add code to pull desired command line through NSUserDefaults.
NSUserDefaults will also pull settings from user preferences
(obviously).
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/UserDefaults/Concepts/DefaultsDomains.html
> What I would like to have is launch my application from the GUI and somehow
> pass the command line parameters to it. If I had to guess, this would be
> encoded in the Info.plist file in the bundle. It is not clear to me how to
> do that. Any feedback would be greatly appreciated.
As others have stated, this is kind of weird and probably the wrong
way to think about it. You should assume that your app will get no
command line arguments on default and set sensible defaults internally
within your app. You might use NSArgumentDomain to provide command
line access for development and backdoor convenience, but not the
common case.
-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden