0

Firefox allows you to run multiple profiles in parallel, which puts multiple icons in the dock. This gets confusing, so my users of my Firefox addon, free open source, requested two features: One to change the icon per their selection per profile. And also they requested that when they do "Keep in Dock" those items, clicking them to start the browser in that profile fails. (It just launches the default profile.) So I've devised a method that will allow them to launch the respective profile on click of "Kept in Dock" icons, on computer restart and window restore, and "Open at Login".

An issue came up because I can now edit the information of persisted dock icons and refresh the dock by editing /Users/noit/Library/Preferences/com.apple.dock.plist. However the non-persisted dock icons are not editable through this method, and I need to set these properties so it opens properly, when a user does "Keep in Dock", restart browser, or restart computer with "open windows from last time".

Here is my current problem:

I'm launching Firefox with a .app I made at /Users/noit/Desktop/dev.app. The shell script in my .app runs this shell:

#!/bin/sh\nexec /Applications/Firefox.app/Contents/MacOS/firefox -P "Default Profile" -no-remote

How to control the bundle-identifier (NOT the CFBundleString but the bundle-string that gets written to com.apple.dock.plist) and file-data :: _CFURLString of my NSApplication via objective-c or core-foundation?

The reason I need this is because certain action sequences change the bundle-string and file-data which causes a redundant icon to pop up in the dock. I have recorded a 3 minute screencast clearly demonstrating this current issue. This screencast clearly shows how extra icons pop up, and the below logically explains why its creating a new icon: Youtube :: Demo :: Reason I need to set bundle-identifier/_CFURLString of non-persisted app

The CFBundleIdentifier in the info.plist of my dev.app is:

<key>CFBundleIdentifier</key>
<string>myCustomBundleIdenter</string>

(note: for convenience i replaced with myCustomBundleIdenter just for this topic post, my real one is in right format)

The following is how the dock icon (/Users/noit/Library/Preferences/com.apple.dock.plist) is reacting - and the source of my troubles.

  1. Now when I double click my dev.app it opens Firefox with this info for it's dock icon with the following bundle-identifier and file-data :: _CFURLString:

     <dict>
         ...
         <dict>
             <key>bundle-identifier</key>
             <string>myCustomBundleIdenter</string>
             ...
             <dict>
                 ...
                 <key>_CFURLString</key>
                 <string>file:///Users/noit/Desktop/dev.app/</string>
                 ...
             </dict>
             ...
         </dict>
        ...
     </dict>
    
  2. Now if I do killall Dock from terminal, it separates my icon because the dock icon is now with a changed file-data :: _CFURLString:

     <dict>
         ...
         <dict>
             <key>bundle-identifier</key>
             <string>myCustomBundleIdenter</string>
             ...
             <dict>
                 ...
                 <key>_CFURLString</key>
                 <string>file:///Applications/Firefox.app/</string>
                 ...
             </dict>
             ...
         </dict>
        ...
     </dict>
    
  3. If I restart Firefox, say after a addon install or something then this splits my icon in dock again due to change in bundle-identifier back to original:

     <dict>
         ...
         <dict>
             <key>bundle-identifier</key>
             <string>org.mozilla.firefox</string>
             ...
             <dict>
                 ...
                 <key>_CFURLString</key>
                 <string>file:///Applications/Firefox.app/</string>
                 ...
             </dict>
             ...
         </dict>
        ...
     </dict>
    

So as we see, my aim is to keep bundle-identifier constant at myCustomBundleIdenter and file-data :: _CFURLString constant at file:///Users/noit/Desktop/dev.app/, any ideas on how to keep this stuff constant programtically via objective-c or core-foundation? So that redundant icons do not pop up, and clicking the non-persisted OR persisted icon will launch properly, even on computer restart with "Open windows from last time".

Worst case scenario, I need to just be able to set the bundle-identifier that gets stored to the com.apple.dock.plist, then I can use file watcher on the com.apple.dock.plist on file changes to see if it was my bundle-string that got "Kept in Dock" and then I can set the file-data :: _CFURLString via edit the com.apple.dock.plist dictionary.

halfer
  • 19,824
  • 17
  • 99
  • 186
Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • What are you actually trying to accomplish? Why are you running FireFox, and why are you trying to give it the custom dock icon of your app? – Alex Nauda Feb 02 '15 at 07:48
  • @Alex, thx. FF allows you to run multiple profiles in parallel, which puts multiple icons in the dock. This gets confusing, so my users of my firefox addon, free open source, requested two features, one change the icon per their selection per profile. And also they requested that when they do "Keep in Dock" those items, clicking them to start the browser in that profile fails, it just launches the default profile. So with this method in this topic, I can allow them to launch the respective profile on click of "Kept in Dock" icons, on computer restart and window restore, and "Open at Login". :) – Noitidart Feb 02 '15 at 08:53
  • One thought I had was: setup global listener, which listens to the path (and command line args) of all app's that are starting up. If it is path to `/Applications/Firefox.app` then I block that startup, and then with my listener I launch it from `/Applications/dev.app` which launches `/Applications/Firefox.app/Content/MacOS/firefox` with command line arg of `-meRelaunch` so my listener won't block it. Is that viable? Thanks @AlexNauda and all who try to help. – Noitidart Feb 02 '15 at 23:24
  • Seems pretty kludgy, but I don't have a better suggestion for you. – Alex Nauda Feb 03 '15 at 15:52
  • Thanks @AlexNauda I tried this solution but ran into a problem. When Firefox closes, the listener shutdown with it, I'll need to figure out how to run the listener in a seperate thread or process or something, very kludy you're right haha. I rather not go down that way haha – Noitidart Feb 03 '15 at 16:28
  • 1
    What about shipping this feature as an NSStatusItem (i.e. menu bar icon app) in addition to your wrapper program? That would also give users a convenient place to set preferences, start on boot, etc. You may even decide to postpone the "keep in dock" feature for now, and recommend that they launch each profile from the status item menu. – Alex Nauda Feb 03 '15 at 19:08
  • Thanks @Alex for that idea, each profile button has some mini icons: [profilist-v1 3-inline-controls](https://cloud.githubusercontent.com/assets/6372489/5240032/274e7652-78ae-11e4-8a7a-275661937cfb.png) so that way won't work :( The icon lights up based on use etc. Lots of features that will go missing if I go with status bar item. I super sincerely appreciate your taking the time to apply your thoughts or my help! :) – Noitidart Feb 03 '15 at 20:21

0 Answers0