Editing Mac OS X login items in Objective-C through AppleScript

Posted by mon4goos on Stack Overflow See other posts from Stack Overflow or by mon4goos
Published on 2010-04-24T02:23:39Z Indexed on 2010/04/24 2:33 UTC
Read the original article Hit count: 450

Filed under:
|
|
|

In my Cocoa program, I want to examine what programs are registered to run at startup and modify that list as I feel appropriate. In order to be compatible with Tiger it seems like I need to work through AppleScript. I currently have the following code:

NSDictionary* errorDict;
NSAppleEventDescriptor* returnDescriptor = NULL;

NSString *appleSource = @"tell application \"System Events\"\n\
get every login item\n\
end tell";
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource: appleSource];

returnDescriptor = [appleScript executeAndReturnError: &errorDict];

If I run that command in AppleScript, I get back an array of login items. However, I can't figure out how to iterate through this array in Objective-C. More specifically, I want to examine the names and paths of the programs registered to run at startup.

Any ideas?

© Stack Overflow or respective owner

Related posts about applescript

Related posts about cocoa