Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Removing Applications from the Dock Programmatically



Thanks to all that helped, here's the code working:

NSUserDefaults *theDefaults = [NSUserDefaults standardUserDefaults];
NSDictionary *dockDict = [theDefaults persistentDomainForName:@"com.apple.dock"];
NSMutableDictionary *mutableDockDict=[dockDict mutableCopyWithZone:nil];

NSArray *apps = [mutableDockDict valueForKey:@"persistent-apps"];
NSMutableArray *newApps=[NSMutableArray arrayWithCapacity:20];
BOOL somethingToRemove=NO;

for(NSDictionary *anApp in apps)
{
NSString *path=[[[anApp valueForKey:@"tile-data"] valueForKey:@"file- data"] valueForKey:@"_CFURLString"];
NSRange range= [path rangeOfString:@"/ pathOfApplicationsIWantToRemove"];

if (range.location != NSNotFound && range.location == 0)
{
NSLog(@"Removing App From Dock at Path:%@",[[[anApp valueForKey:@"tile-data"] valueForKey:@"file-data"] valueForKey:@"_CFURLString"]);
somethingToRemove=YES;
}
else
{
[newApps addObject:anApp];
}
}
if (somethingToRemove)
{
[mutableDockDict setObject:newApps forKey:@"persistent-apps"];
[theDefaults setPersistentDomain:mutableDockDict forName:@"com.apple.dock"];

//
// Kill Dock
//
NSString *quitSource = @"tell application \"/System/Library/ CoreServices/Dock.app\" to quit";
NSAppleScript *quitScript = [[[NSAppleScript alloc] initWithSource:quitSource] autorelease];
NSDictionary *theError = [[[NSDictionary alloc] init] autorelease];


		[quitScript executeAndReturnError:&theError];	
	}
        [NSApp terminate:nil];

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Removing Applications from the Dock Programmatically (From: Kevin Kicklighter <email@hidden>)
 >Re: Removing Applications from the Dock Programmatically (From: Graff <email@hidden>)
 >Re: Removing Applications from the Dock Programmatically (From: Negm-Awad Amin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.