2009-03-08 9 views

Répondre

3

Le taux de croissance est de open source.

+0

Ouais, mais nous le faisons de la vieille façon suceuse. La nouvelle hotness est la liste des fichiers partagés, que nous n'utilisons pas encore. ☺ –

+0

Oui, je n'ai pas vraiment vérifié comment tu l'as fait. Je voulais juste souligner que xPablo a déjà posté sa propre solution d'une certaine façon;) –

0

Copiez cette partie du code dans le fichier .m: [? Enregistrez-vous comme Connexion article avec Cocoa]

- (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); 
} 
+2

Ceci est utile (je pense), mais s'il vous plaît le formater et le lier à la source! –

Questions connexes