Sign up ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I am using a commandline script to add items to the dock via scripts

But it seems to have a lot of bugs and maybe even "kills" my Dock config file. Are there any good alternatives out there to add *.app properly to the dock ?

share|improve this question
Do you have the latest version? Latest version : – henri Apr 6 at 0:52

1 Answer 1

Open Applications / Utilities / AppleScript Editor and paste this:

my add_item_to_dock(choose file of type {"APPL"} with prompt "Choose an application to add to the Dock:")
on add_item_to_dock(item_path)
        get item_path as alias -- you need a POSIX path so this coerces the path in case it's an HFS path, alias, file ref, etc.
        set item_path to POSIX path of item_path
    end try
        tell application "Dock" to quit
    end try
    do shell script "defaults write persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & item_path & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
        tell application "Dock" to activate
    end try
end add_item_to_dock

Save it as Script or Application.

share|improve this answer
Can i directly use it in my "normal" shell script as function ? Or won't it work because its apple script – Dukeatcoding Sep 18 '12 at 7:41
To Run and AppleScript from shell you'll need to use the osascript command. You can either call the AppleScript directly (osascript -e 'applescript command') or run the script (osascript script.scpt). If you are parsing the AppleScript directly, you'll need to rephrase it so it can be run in one line. – Thecafremo Sep 18 '12 at 7:59
You can also include newlines in the argument after -e, get the script from stdin, or use a HEREDOC. – ؘؘؘؘ Sep 18 '12 at 8:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.