0

I have a .app. I want to edit the plist.Info such that if a command line argument of -P "main" is in the path it will use another of the icons in my resources folder. And if user right clicked and said "keep in dock" it will keep in dock with command line arguments, so on next click it will launch with same command line arguments.

Is this possible?

Worst cast scenario: Any objective-c way to check the path to see if any command line arguments there? Then I'll run setApplicationIconImage programtically (worst case meaning if the above is not possible) (and then ill also have to programtically fetch the miniaturized windows with [NSWindow miniwindowImage] and draw the mini icon on their msyelf and also listen to future notifications of NSWindowWillMiniaturizeNotification and do the draw when that notification fires, so this is worst case scenario)

Noitidart
  • 35,443
  • 37
  • 154
  • 323

1 Answers1

1

I am not sure I follow you fully.

But I don't think you need to edit the plist.Info and I think it is not good to do that any way.

I would just to write to the apps preference file with CFPreferencesSetValue and change an entry which determines if the app changes it's icon.

Call made from you argument check:

 [self changIcon:(CFBooleanRef)false];

-(void) changIcon:(CFBooleanRef)prefValue
{


    CFStringRef appID = CFSTR("com.yourApp.BundleID");
    CFStringRef Key = CFSTR("swapIcon");
    CFBooleanRef Value = prefValue ;// kCFBooleanTrue;//or kCFBooleanFalse

    // Set up the preference.
    CFPreferencesSetValue(Key,
                          Value,
                          appID,
                          kCFPreferencesCurrentUser,
                          kCFPreferencesAnyHost);

    // Write out the preference data.
    CFPreferencesSynchronize(appID,
                             kCFPreferencesCurrentUser,
                             kCFPreferencesAnyHost);

}

Change the icon

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];

   BOOL  swapIcon = [defaults boolForKey:@"swapIcon"];

    if (swapIcon ) {
         NSImage * b1Image = [NSImage imageNamed:@"bl1"];
         [NSApp  setApplicationIconImage:b1Image];
    }else {
        [NSApp  setApplicationIconImage:nil];//--Nil will make the app use thenormal icon
    }

For a better answer you would need to explain a bit more clearly.

markhunte
  • 6,805
  • 2
  • 25
  • 44
  • Thanks very much for trying to answer and thanks for asking for clarity when you couldnt understand, instead of ignoring it. I have this app `Applications/Firefox.app`, if I launch that from terminal with command line arguments `-P "profile name" -no-remote` it will launch profile in paralell. – Noitidart Jan 23 '15 at 06:38
  • I am trying to keep in dock seperate icons for this. Right now if i click the icons in the dock it opens up Firefox but if i keep in dock it opens regular (w/o command line arguments). I also want to set custom image on them. `setApplicationIconImage` doesn't change the mini version of the icon of the miniaturized windo :( – Noitidart Jan 23 '15 at 06:39
  • 1
    @Noitidart Do you mean you want to write a command line app that will launch a new instance of Firefox.app, and give it it's own icon and dock item. Am not sure thats possible – markhunte Jan 23 '15 at 14:30
  • What i've done right now is write a App with shell script inside it, which launches "/Applications/Firefox.app/Contents/MacOS/firefox -P "prof name" -no-remote". It launches with the icon i gave my app, different profiles get their own icon. However if I restart firefox. Or if I restart computer with option "Reopen apps" it comes back as separate icon, as the regular Firefox.app icon. So I'm having trouble there, keeping Firefox open but to always show that app instead of its own icon. :( Thanks again for your time man! – Noitidart Jan 23 '15 at 15:24
  • I studied this and its quite useful thanks for sharing it i accepted it :) – Noitidart Feb 27 '15 at 22:32