Re: Add app to "launch on startup" list via AppleScript
Re: Add app to "launch on startup" list via AppleScript
- Subject: Re: Add app to "launch on startup" list via AppleScript
- From: Chunk 1978 <email@hidden>
- Date: Mon, 8 Jun 2009 20:00:10 -0400
if you're distributing for Leopard only, use this:
-=-=-=-=-=-=-=-
@interface Preferences (PrivateMethods)
- (void)enableLoginItemWithLoginItemsReference:(LSSharedFileListRef
)theLoginItemsRefs
ForPath:(CFURLRef)thePath;
- (void)disableLoginItemWithLoginItemsReference:(LSSharedFileListRef
)theLoginItemsRefs
ForPath:(CFURLRef)thePath;
@end
@implementation Preferences (PrivateMethods)
- (void)enableLoginItemWithLoginItemsReference:(LSSharedFileListRef
)theLoginItemsRefs
ForPath:(CFURLRef)thePath
{
LSSharedFileListItemRef item = LSSharedFileListInsertItemURL
(theLoginItemsRefs, kLSSharedFileListItemLast, NULL, NULL, thePath, NULL,
NULL);
if (item)
{
CFRelease(item);
}
}
- (void)disableLoginItemWithLoginItemsReference:(LSSharedFileListRef
)theLoginItemsRefs
ForPath:(CFURLRef)thePath
{
UInt32 seedValue;
NSArray *loginItemsArray = (NSArray
*)LSSharedFileListCopySnapshot(theLoginItemsRefs,
&seedValue);
for (id item in loginItemsArray)
{
LSSharedFileListItemRef itemRef = (LSSharedFileListItemRef)item;
if (LSSharedFileListItemResolve(itemRef, 0, (CFURLRef*) &thePath, NULL) ==
noErr)
{
if ([[(NSURL *)thePath path] hasPrefix:DeskguiseApplicationPath])
LSSharedFileListItemRemove(theLoginItemsRefs, itemRef);
}
}
[loginItemsArray release];
}
@end
-=-=-=-=-=-=-=-=-
On Mon, Jun 8, 2009 at 7:15 PM, Martin Batholdy <email@hidden>wrote:
> Hi,
>
> I have the following AppleScript that let me add an application to the
> "launch on startup" menu:
>
> tell application "System Events"
> make login item at end with properties {path:"...",
> kind:application}
> end tell
>
> The script works fine when I start it in the script editor for
> AppleScripts.
>
> But when I implement it in my cocoa app, the code is executed properly
> (when I copy the code that is created out of the log window and start it in
> the script editor it works) - but the app don't appear in the "launch on
> startup" menu under preferences -> users ...
>
> Does my app have the propper rights to do that?
> Is that the problem?
>
>
>
> thanks for any help!
>
> _______________________________________________
>
> 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
>
_______________________________________________
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