Skip navigation

Remove from dock

2367 Views 8 Replies Latest reply: Dec 14, 2013 7:54 AM by El Gaucho RSS
John Antolino Calculating status...
Currently Being Moderated
Apr 28, 2012 6:35 AM

 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)
  • Carolyn Samit Level 10 Level 10 (84,015 points)
    Currently Being Moderated
    Apr 30, 2012 5:03 AM (in response to John Antolino)

    Hi...

     

    Would it not be easier to just drag the icon straight up off the Dock so it goes, "poof" ...

     

    Applications cannot be stored in the Dock.

  • twtwtw Level 5 Level 5 (4,580 points)
    Currently Being Moderated
    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

  • bosilkovska Calculating status...
    Currently Being Moderated
    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!

  • Mark Jalbert Level 5 Level 5 (4,385 points)
    Currently Being Moderated
    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.

  • El Gaucho Calculating status...
    Currently Being Moderated
    Dec 14, 2013 7:31 AM (in response to Mark Jalbert)

    Great! Would there be a way to do the same to add an app too? My scenario is that I need to remove an app from the dock and add another. If I could do this in a single call that would be great.

     

    Thoughts?

     

    Stephen

  • El Gaucho Level 1 Level 1 (0 points)
    Currently Being Moderated
    Dec 14, 2013 7:54 AM (in response to twtwtw)

    This is not working for me in Mavericks. Has anything changed?

     

    EDITED: I removed the carriage returns in the text for the terminal and it worked just fine.

     

    Is there a way to do the same but to add an application?

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.