Hello,

How to create a shortcut for an application on the MAC OS Dock? Also change its icon?

asked 03 May '13, 16:48

Codename%20K's gravatar image

Codename K
246596371
accept rate: 50%


You can use the defaults command to add an application to dock.

You also need to restart the Dock application to refresh changes.

For example:

<runProgram> <program>defaults</program> <programArguments>write com.apple.dock persistent-apps -array-add ' &lt;dict&gt; &lt;key&gt;tile-data&lt;/key&gt; &lt;dict&gt; &lt;key&gt;file-data&lt;/key&gt; &lt;dict&gt; &lt;key&gt;_CFURLString&lt;/key&gt; &lt;string&gt;${installdir}/your.app&lt;/string&gt; &lt;key&gt;_CFURLStringType&lt;/key&gt; &lt;integer&gt;0&lt;/integer&gt; &lt;/dict&gt; &lt;/dict&gt; &lt;/dict&gt;' </programArguments> </runProgram> <runProgram> <program>killall</program> <programArguments>-HUP Dock</programArguments> </runProgram>

The first command registers the application in the dock. You will need to change the path from ${installdir}/your.app to actual path to the .app bundle. The second command restarts the Dock program.

Also, please note that if your installer is running as administrator (i.e. by setting <requireInstallationByRootUser> set to 1), you need to run su command to run the defaults command as appropriate user.

link

answered 06 May '13, 02:52

wojciechka's gravatar image

wojciechka ♦♦
7.8k61122
accept rate: 26%

Perfect. Worked without a hitch. Now if we are uninstalling the program then how to remove the dock icon?

(07 May '13, 08:13) Codename K

Unfortunately removing it is not as easy as it would require manually retrieving and changing the array.

However, Mac OS X should detect that the application was uninstalled and automatically remove it from the dock. Is it not the case? If not, perhaps running killall -HUP Dock causes it to refresh?

(08 May '13, 05:37) wojciechka ♦♦

Thanks. You have to use a AppleScript. You need to run this at uninstallation. Replace the 'dockappname' with the dock icon name,

try tell application "System Events" set dockPlistFile to property list file "~/Library/Preferences/com.apple.dock.plist" tell dockPlistFile tell property list item "persistent-apps" set appTileItems to value of (every property list item whose value of property list item "tile-data"'s property list item "file-label" is not "dockappname") set its value to appTileItems end tell end tell end tell tell application "Dock" to quit end try

(08 May '13, 05:46) Codename K

To remove the Dock icon you have to use a AppleScript. You need to run this at uninstallation. Replace the 'dockappname' with the dock icon name,

try
    tell application "System Events"
        set dockPlistFile to property list file "~/Library/Preferences/com.apple.dock.plist"
        tell dockPlistFile
            tell property list item "persistent-apps"
                set appTileItems to value of (every property list item whose value of property list item "tile-data"'s property list item "file-label" is not "dockappname")
                set its value to appTileItems
            end tell
        end tell
    end tell
    tell application "Dock" to quit
end try
link

answered 08 May '13, 05:48

Codename%20K's gravatar image

Codename K
246596371
accept rate: 50%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×130
×42
×29
×15
×6

Asked: 03 May '13, 16:48

Seen: 5,211 times

Last updated: 08 May '13, 05:48