Re: best way to launch an application with an NSArray argument
Re: best way to launch an application with an NSArray argument
- Subject: Re: best way to launch an application with an NSArray argument
- From: Douglas Davidson <email@hidden>
- Date: Fri, 18 Jan 2002 10:07:00 -0800
On Friday, January 18, 2002, at 01:54 AM, Angela Brett wrote:
This is probably a bit of a newbie question... I want my app to launch
another one, passing it an NSArray and an integer. I have tried using
environment variables in an NSTask but that doesn't work with the
NSArray, it's only happy if I use a string instead. I guess I could
post a notification with the information after the app has opened, or
write the array to a plist file before opening the other application,
or something like that... but that seems kind of kludgy. What is the
best way to open an application and send it an array to work with? I
don't need to send it any information while it is running, just those
two things when it first starts up.
Environment variables and command-line arguments are C strings; if you
want to pass an array that way, you'll need to write it out as a
string. If it's a property list, it can be written out in XML plist
format; there might be escaping issues depending on exactly how you pass
it. There is also the old ASCII plist format, in which an array is
written as e.g. (foo, bar) which is more convenient in some cases but
might have encoding issues. The same methods that read XML plists will
read that format as well. One example is that it is possible to set
defaults for a single execution of an application by passing them as
command-line arguments, in the format -<key> <value>; for example,
/Applications/TextEdit.app/Contents/MacOS/TextEdit -AppleLanguages
"(French, English)" &
will launch TextEdit in French.
Douglas Davidson