Le 2 juil. 08 à 16:58, Jason Coco a écrit :

Yeah, to me it is... although I still agree that it's not an ideal solution for a Cocoa application...

By the way, assuming you change char *args[] = { "-a", "Safari", NULL }; to char *args[] = { "/usr/bin/open", "-a", "Safari", NULL }; the exec* example actually works while the LaunchServices example fails with kLSApplicationNotFoundError.


Mail is not a very good IDE ;-)


After playing around with it a little, I discovered that you need to actually call it CFSTR("Safari.app") in this case to get it to work correctly... so like anything else in life, since I'm much more familiar with the POSIX/BSD API (and since pretty much every operating system I've ever worked with treats exec* similar) it's a lot easier *for me* than using LaunchServices.

OK.

In fact, I never use LS with app name but with bundle ID instead. It's far more reliable.

LSFindApplicationForInfo(kLSUnknownCreator, CFSTR("com.apple.Safari"), NULL, &app, NULL)


On Jul 2, 2008, at 03:30 , Jean-Daniel Dupas wrote:

"a lot easier than Launch Services" ?

extern char **environ;
char *args[] = { "-a", "Safari", NULL};
execve("/usr/bin/open", args, environ);

versus:

FSRef app;
if (noErr == LSFindApplicationForInfo(kLSUnknownCreator, NULL, CFSTR("Safari"), &app, NULL))
        LSOpenFSRef(&app, NULL);



Le 2 juil. 08 à 06:45, Jason Coco a écrit :

What env pollution? I agree that exec* isn't really the way to go, but that's what the OP was using... I just suggested that /usr/bin/ open is a better option than hard-coding the path to some arbitrary application. It's also a lot easier to use than the LaunchServices API... although if I were gonna use it, I'd definitely do so from an NSTask object as others have already suggested.

On Jul 1, 2008, at 23:44 , Kyle Sluder wrote:

On Tue, Jul 1, 2008 at 8:17 PM, Kevin Elliott <[EMAIL PROTECTED]> wrote:
Of course, they're both bad choices. As several people have pointed out, NSWorkspace launchApplication or openURL depending on the requirements. If it's not possible to use NSWorkspace (i.e. because you can't link against AppKit) consider NSTask or using LaunchServices. But unless you have a
SPECIFIC, low level requirement exec is the wrong API.

I was even more concerned about the env pollution necessary for exec to work as described ("not needing to know where Safari lives"). exec
is just a bad idea all around for anything outside of the BSD
environment.

--Kyle Sluder

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/devlists%40shadowlab.org

This email sent to [EMAIL PROTECTED]



Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to