• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSApplication and command line args
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSApplication and command line args


  • Subject: Re: NSApplication and command line args
  • From: Ken Thomases <email@hidden>
  • Date: Sun, 10 May 2009 00:05:43 -0500

On May 8, 2009, at 5:03 PM, Andrew Farmer wrote:

A much simpler solution would be to preprocess the arguments which you pass to NSApplicationMain. Run through everything in argv, then create a new array of arguments from that with all arguments your application wants to handle removed and pass that to AppKit.

This doesn't work. As the documentation for NSApplicationMain notes, it doesn't actually make any use of the argc and argv parameters it receives. Instead, it just looks at the original argument list using _NSGetArgc() and _NSGetArgv().


That makes it pretty much impossible to integrate your own scheme for command-line arguments that differs from what Cocoa expects. Cocoa will allow you to set defaults in the NSArgumentDomain domain using pairs like -<default> <value>, and it will process other arguments as files to open, as you've seen.

If you need to process command line arguments, you either have to follow the above scheme or write a non-application (a.k.a. a command- line tool).


Brian, your proposed scheme of essentially disabling the - application:openFiles: delegate method until after - applicationDidFinishLaunching: will probably work. Have you considered using the defaults system for the control of your application that you're seeking to do with command-line switches? If you do that, you should get argument processing "for free". This does require that all switches have a value, which may entail changing present/absent switches to boolean-valued defaults (e.g. "- enableFrobozzingOfWizbangs YES" instead of merely "- enableFrobozzingOfWizbangs"). It also doesn't work if you allow the use of a given switch multiple times to accumulate values. So, it doesn't work for all purposes, but it might for yours.


Regards,
Ken

_______________________________________________

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


References: 
 >NSApplication and command line args (From: Brian Arnold <email@hidden>)
 >Re: NSApplication and command line args (From: Andrew Farmer <email@hidden>)

  • Prev by Date: WebView PolicyDelegate issue
  • Next by Date: Re: Hex to NSString or NSData
  • Previous by thread: Re: NSApplication and command line args
  • Next by thread: Converting NSString to C++ std::string
  • Index(es):
    • Date
    • Thread