Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Remove from dock

Can I just remove an icon from the dock using terminal.


I would like to remove the app from the dock as well, Like most uninstallers do.

I usually see them kill the dock


do shell script "killall Dock"


But how do I remove the app?

--------


At the moment I added some GUI Scripting but I would perfer not to use GUI scripting, because its a bit flaky.

Sometimes I noticed assistive device's says its on but the script does not always work stating that it is not on.


do shell script "touch /private/var/db/.AccessibilityAPIEnabled" with administrator privileges


try

tell application "XYZ" to quit

delay 0.5 -- adjust if necessary

tell application "System Events" to tell UI element "XYZ" of list 1 of process "Dock"


perform action "AXShowMenu"

click menu item "Options" of menu 1

click menu item "Remove from Dock" of menu 1 of menu item "Options" of menu 1

end tell

end try

MacBook Pro, Mac OS X (10.7.3)

Posted on Apr 28, 2012 6:35 AM

Reply
8 replies

Apr 30, 2012 1:45 PM in response to John Antolino

To remove an item from the dock using applescript, you can use the following (it makes a list of all the persistent-apps entries that are not the one you're trying to remove, and rewrites that list to the plist file):


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 "app name")

set its value to appTileItems

end tell

end tell

end tell

tell application "Dock" to quit

Jul 24, 2012 2:27 AM in response to twtwtw

Hi,

How can I use it in command line?


osascript '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 "app name") set its value to appTileItems end tell end tell end tell tell application "Dock" to quit'


or


osascript -e '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 "app name") set its value to appTileItems end tell end tell end tell tell application "Dock" to quit'


but I get: -bash: syntax error near unexpected token `)'


Any idea?

Thanks!

Jul 24, 2012 5:21 AM in response to bosilkovska

From the command line you could do it like this->

#Change name_of_app to the app you want to remove
dloc=$(defaults read com.apple.dock persistent-apps | \
grep _CFURLString\" | \
awk '/name_of_app/ {print NR}'
)
/usr/libexec/PlistBuddy -c "Delete persistent-apps:$dloc" ~/Library/Preferences/com.apple.dock.plist
killall Dock


Message was edited by: Mark Jalbert Problems with bk awk.

Remove from dock

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.