A caveat: typeApplicationBundleID just picks whichever target if there is more than one instance of an app with the same bundle id running. This can be the case if, for example, you're running both the current version of PowerPoint and an older version. typeProcessSerialNumber will always target the specified process.
To go from pid to PSN, you can use the Process Manager's GetProcessForPID(). This will require you to link in -framework ApplicationServices. To send high-level events, you'll not only need to have a connection to the window server, but, depending on what you're doing, the Mach bootstrap namespace might also be an issue. See TN2083 "Daemons and Agents" for further details. —Jeremy On Mon, Apr 13, 2009 at 8:45 PM, Bill Janssen <jans...@parc.com> wrote: > "From the command line"... > > Luca C. <luca.pazzere...@gmail.com> wrote: > >> 2009/4/13 Bill Janssen <jans...@parc.com> >> > >> > >> > I was afraid of that... Is there an easy way to do that from the >> > command line given its PID? >> >> >> Using an AppleEvent given the appropriate bundle id of the application is >> actually pretty easy.I have found this in one my quite old project: >> >> + (OSStatus)quitApplicationWithBundleID:(NSString *)aBundleID { >> >> OSStatus err; >> >> AppleEvent event, reply; >> >> const char *bundleIDString; >> >> >> >> bundleIDCString = [aBundleID UTF8String]; >> >> >> >> err = AEBuildAppleEvent(kCoreEventClass, kAEQuitApplication, >> typeApplicationBundleID, >> >> bundleIDCString, strlen(bundleIDCString), >> kAutoGenerateReturnID, >> >> kAnyTransactionID, &event, NULL, ""); >> >> >> >> if (err == noErr) { >> >> err = AESendMessage(&event, &reply, kAENoReply, kAEDefaultTimeout); >> >> AEDisposeDesc(&event); >> >> } >> >> return err; >> >> } >> >> >> Haven't tested with Leopard yet, but I'm sure it works there. >> >> >> HTH >> >> --Luca C. >> _______________________________________________ >> >> 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/janssen%40parc.com >> >> This email sent to jans...@parc.com > _______________________________________________ > > 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/jeremyw.sherman%40gmail.com > > This email sent to jeremyw.sher...@gmail.com > _______________________________________________ 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 arch...@mail-archive.com