Load WordPress Sites in as fast as 37ms!

Handy Shell Scripts – part II – manage_launchpad.sh

The second script I’d like to share is one to list or delete items from the OSX Lion launchpad. It’s a very basic script with semi-cryptic output, but it’s useable for the two or three times you’ll ever use it.

Have you looked at your launchpad? It probably has twenty or more items you would like removed, but, …., OSX doesn’t allow you to remove items. Luckily it’s just an SQLITE database and with a few carefully built SQL queries, we can cleanup duplicates and unwanted items.

How to use;

Shell commandmanage_launchpad.sh list

Will output a list like;

Shell output1Password|3|ws.agile.1Password
Acrobat Distiller|11|com.adobe.distiller
Activity Monitor|462|com.apple.ActivityMonitor
Address Book|5|com.apple.AddressBook
Adium|6|com.adiumX.adiumX
Adium|75|com.adiumX.adiumX
Adobe Acrobat Pro|16|com.adobe.Acrobat.Pro
Adobe After Effects CS5|18|com.adobe.AfterEffects
Adobe After Effects Render Engine|20|Adobe After Effects Render Engine
Adobe Bridge CS5|32|com.adobe.bridge4

First is the NAME of the item, the second is the ID. The third one (bundle_id) I have used to determine the company behind certain items.

If you have a duplicate item, you can make this list a bit more specific;

Shell commandmanage_launchpad.sh list Adium

Shell outputAdium|6|com.adiumX.adiumX
Adium|75|com.adiumX.adiumX

Now write down the items you wish to remove by ID. In this case, 75.

Shell commandmanage_launchpad.sh delete 75

The Dock (which is responsible for the Launchpad) is restarted automatically.

The more observant of you will notice an “undocumented” feature; delete_no_restart . This will delete the item, but not restart the Dock.

Shell commandmanage_launchpad.sh delete_no_restart 75

The script:

Shell-Script
#!/bin/sh [ "$1" == "" ] && echo Usage: $0 list \<optional title\> && echo or…. $0 delete \<required item_id\> && exit;
if [ "$1" == "list" ]; then
sqlite3 ~/Library/Application\ Support/Dock/*.db "SELECT title, item_id, bundleid FROM apps WHERE title LIKE '%$2%' ORDER BY title ASC;" && exit
fi
DR=yes
OP=$1
[ "$1" == "delete_no_restart" ] && DR=no && OP=delete if [ "$OP" == "delete" ]; then
[ "$2" == "" ] && echo Usage: $0 delete \'App ID\' && exit;
sqlite3 ~/Library/Application\ Support/Dock/*.db "DELETE from apps WHERE item_id=$2;" && [ "$DR" == "yes" ] && killall Dock
fi

Author: Remon Pel

WebDeveloper though not WebDesigner

2 thoughts on “Handy Shell Scripts – part II – manage_launchpad.sh”

  1. i’ve been playing around with the dock’s sqlite db for a while now and i’ve noticed one thing that might help you improve your script. the db has triggers defined to clean up stuff on delete from the items table. your script is deleting from the apps table, which has no triggers associated with it. if you change your script to delete from items where rowid=$2 instead, then the trigger item_deleted will get invoked and also delete from apps with the same item_id. other cleanup activities are invoked in that trigger too; for example, it will remove the item from any groups it was in, among other things. i think the items table is the root of all data and the apps table is just used for friendly display lookup, like what to print for the icon’s display name; it’s just a metadata table.

    also i have noticed that the mac has some built-in event which i can’t put my finger on where it comes in and regenerates the entire launchpad db to add in any missing applications. i like to setup my launchpad with just the two dozen or so apps that i use regularly, but the mac won’t let me keep the launchpad that clean.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.