Add item to Dock

Sharing and discussing custom actions for LaunchBar
Post Reply
Kicweed
Rank 1
Rank 1
Posts: 23
Joined: Sun Nov 09, 2008 3:25 am
Contact:

Add item to Dock

Post by Kicweed » Mon Dec 13, 2010 10:12 am

I would like to be able to add the selected item in LB to the Dock, without using the mouse. I use the Dock as a to-do list and I want to add newly downloaded apps or documents to it. Finding the app or document is easy with LB, but having to use the mouse to add it to the Dock breaks keyboard-only flow. I'd love to be able to do the following:

1. Invoke LB
2. Locate the item in question
3. Hit TAB
4. Select the "Add to Dock" action

Result: If it is an app it appears to the left side with all the apps. If it is a file or folder, it appears to the right side.

I don't care where on the Dock the item appears, as long as it is there. How could this be done with an Applescript action? Could I also do the reverse, get a list of the items on the Dock and remove any one of them?

Thanks in advance.

manfred
Objective Development
Objective Development
Posts: 561
Joined: Sat Jul 31, 2010 9:47 am
Location: Vienna
Contact:

Re: Add item to Dock

Post by manfred » Mon Dec 20, 2010 2:56 pm

Kicweed,

an example script which adds an application to the dock. Unfortunately it is necessary to restart the dock to see the changes. Thereby all minimized application are removed from the dock.

Code: Select all

on open (dockApp)
   set dockAppPOSIX to POSIX path of dockApp

   do shell script "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & dockAppPOSIX & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"

    do shell script "killall -HUP Dock"
end open


If the script shall work for files it is necessary to replace »persistent-apps« by »persistent-others«.

Kicweed
Rank 1
Rank 1
Posts: 23
Joined: Sun Nov 09, 2008 3:25 am
Contact:

Re: Add item to Dock

Post by Kicweed » Tue Dec 21, 2010 4:28 pm

After some searching I've found the dockutil program that makes adding, replacing and removing items from the Dock a breeze. It's a Python program that provides a standardized syntax for adding apps and files to the Dock. I haven't found the time to incorporate it in my LB workflow, but it should be simple to build an AppleScript wrapper around it and call it from LB.

https://code.google.com/p/dockutil/

Post Reply