Cocoa – Add Application to Dock
Here’s a little snippet of code for placing anything (or your application) in a user’s Dock. Wrote it for a project I’m working on which prompts the user on first launch to place in Dock for them. I know many people disagree with this (as do I), but it’s what the client is paying for.
1 2 3 4 5 6 7 8 9 10 11 12 | // Places an icon in the user's dock
- (void) addToDock:(NSString*) path {
NSLog(@"Adding %@ to dock", path);
NSAppleScript* placeInDock = [[[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"do shell script \"defaults write com.apple.dock persistent-apps -array-add 'tile-datafile-data_CFURLString%@_CFURLStringType0'\"", path]] autorelease];
[placeInDock executeAndReturnError:nil];
NSAppleScript* killDock = [[[NSAppleScript alloc] initWithSource:@"tell application \"Dock\" to quit\nlaunch application \"Dock\""] autorelease];
[killDock executeAndReturnError:nil];
} |
The parameter path needs to be an expanded path.
August 31, 2009 1:30 pm
Add a comment














Submitting Your Comment, give me a second...