Re: Removing Applications from the Dock Programmatically
Re: Removing Applications from the Dock Programmatically
- Subject: Re: Removing Applications from the Dock Programmatically
- From: Kevin Kicklighter <email@hidden>
- Date: Wed, 27 Aug 2008 13:48:52 -0400
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:
This email sent to email@hidden