Ajouter une application aux & # 8220; Articles de démarrage & # 8221;
Question
Certaines applications ont un bouton de vérification pour "démarrer à la connexion" ...
.Commencez à l'ouverture de session http: //b2.s3.p.quickshareit. com / files / growlstartup49525.png
Comment mettriez-vous cela en œuvre?
La solution
Cela se fera, selon Justin Williams: http://carpeaqua.com/2008/03/01/adding-an-application-to-login-items-in-mac-os-x-leopard/
Autres conseils
Voir ma réponse à la question précédente S'inscrire en tant qu'élément de connexion dans Cocoa .
Growl est en open source .
Copiez cette partie du code dans le fichier .m:
- (void)awakeFromNib
{
[self setShouldStartGrowlAtLogin:1];
}
- (BOOL) shouldStartGrowlAtLogin {
Boolean foundIt = false;
//get the prefpane bundle and find GHA within it.
NSBundle *prefPaneBundle = [NSBundle bundleWithIdentifier:@"com.yourcompany.Menu_Item"];
NSString *pathToGHA = [prefPaneBundle bundlePath ];
//pathToGHA = [pathToGHA stringByAppendingPathComponent: @"/Contents/MacOS/Menu\ Item"];
NSLog(@"%@", pathToGHA);
if(pathToGHA) {
//get the file url to GHA.
CFURLRef urlToGHA = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)pathToGHA, kCFURLPOSIXPathStyle, true);
UInt32 seed = 0U;
NSArray *currentLoginItems = [NSMakeCollectable(LSSharedFileListCopySnapshot(loginItems, &seed)) autorelease];
for (id itemObject in currentLoginItems) {
LSSharedFileListItemRef item = (LSSharedFileListItemRef)itemObject;
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
CFURLRef URL = NULL;
OSStatus err = LSSharedFileListItemResolve(item, resolutionFlags, &URL, /*outRef*/ NULL);
if (err == noErr) {
foundIt = CFEqual(URL, urlToGHA);
CFRelease(URL);
if (foundIt)
break;
}
}
CFRelease(urlToGHA);
}
else {
NSLog(@"APP: your install is corrupt, you will need to reinstall\nyour prefpane bundle is:%@\n your pathToGHA is:%@", prefPaneBundle, pathToGHA);
}
return foundIt;
}
- (void) setShouldStartGrowlAtLogin:(BOOL)flag {
//get the prefpane bundle and find GHA within it.
NSBundle *prefPaneBundle = [NSBundle bundleWithIdentifier:@"com.yourcompany.Menu_Item"];
NSString *pathToGHA = [prefPaneBundle bundlePath ];
[self setStartAtLogin:pathToGHA enabled:1];
}
- (void) setStartAtLogin:(NSString *)path enabled:(BOOL)enabled {
OSStatus status;
CFURLRef URLToToggle = (CFURLRef)[NSURL fileURLWithPath:path];
LSSharedFileListItemRef existingItem = NULL;
UInt32 seed = 0U;
NSArray *currentLoginItems = [NSMakeCollectable(LSSharedFileListCopySnapshot(loginItems, &seed)) autorelease];
for (id itemObject in currentLoginItems) {
LSSharedFileListItemRef item = (LSSharedFileListItemRef)itemObject;
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
CFURLRef URL = NULL;
OSStatus err = LSSharedFileListItemResolve(item, resolutionFlags, &URL, /*outRef*/ NULL);
if (err == noErr) {
Boolean foundIt = CFEqual(URL, URLToToggle);
CFRelease(URL);
if (foundIt) {
existingItem = item;
break;
}
}
}
if (enabled && (existingItem == NULL)) {
NSString *displayName = [[NSFileManager defaultManager] displayNameAtPath:path];
IconRef icon = NULL;
FSRef ref;
Boolean gotRef = CFURLGetFSRef(URLToToggle, &ref);
if (gotRef) {
status = GetIconRefFromFileInfo(&ref,
/*fileNameLength*/ 0, /*fileName*/ NULL,
kFSCatInfoNone, /*catalogInfo*/ NULL,
kIconServicesNormalUsageFlag,
&icon,
/*outLabel*/ NULL);
if (status != noErr)
icon = NULL;
}
LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst, (CFStringRef)displayName, icon, URLToToggle, /*propertiesToSet*/ NULL, /*propertiesToClear*/ NULL);
} else if (!enabled && (existingItem != NULL))
LSSharedFileListItemRemove(loginItems, existingItem);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow