• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Removing Applications from the Dock Programmatically
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Removing Applications from the Dock Programmatically
      • From: "Sherm Pendley" <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>)

  • Prev by Date: Re: Core Data - use of simple accessors vs. KVC
  • Next by Date: Re: confused about allocating and releasing objects
  • Previous by thread: Re: Removing Applications from the Dock Programmatically
  • Next by thread: Re: Removing Applications from the Dock Programmatically
  • Index(es):
    • Date
    • Thread