Remove Applications from Location Services in Security & Privacy on OS X 10.8

After removing an application in OSX 10.8 it still showed up in location services under the security and privacy settings in system preferences. (see picture below)
The reason is that it saves the entries in a binary plist file. You could delete the file and OSX will automatically recreate it. However you would have to re-authorize all the apps that you previously had authorized.
The following process shows how to edit the file and just remove the single application.

Preparation

1. Start terminal and then sudo to a root shell

sudo -s

2. Navigate to /var/db/locationd

 cd /var/db/locationd

3. Make a backup of the clients.plist file

cp -p clients.plist clients.plist.save

4. The plist file is in binary format and to make it editable/readable you need to convert it to xml

plutil -convert xml1 clients.plist

Edit the file

5. Use vi (vim) to edit the clients.plist file and remove the application

vi clients.plist

6. The file will likely contain many application entries. Here is the format of a single application entry (Safari in this case). The entire entry needs to be deleted. (dd for deleting complete lines in vi)

com.apple.Safari  

Authorized

BundleId
com.apple.Safari
Executable
/Applications/Safari.app/Contents/MacOS/Safari
LocationTimeStopped
376348187.80421197
Registered
/Applications/Safari.app/Contents/MacOS/Safari
RequirementString
identifier "com.apple.Safari" and anchor apple
Whitelisted


7. Convert the clients.plist file back to binary format

plutil -convert binary1 clients.plist

8. Restart locationd daemon by force-killing it. Launchd will automatically restart the daemon

killall locationd

In case things go badly, then copy back the original file and restart locationd

cp -p clients.plist.save clients.plist
killall locationd

This should remove the invalid entries from the security and privacy tab in system preferences.