Sunday, October 5, 2014


Cocoa Uninstall Application script for mac


There are very few people who create application for mac but when they create they forgot to delete their resources from stored location or many developers don’t find correct way to delete resources when Application Move to Trash.
I have also come to the same state after developing my first App , i saw that many resources are not getting deleted so after doing lot of research on web i found some solution . So , i thought to share with other developers too…
Steps are as below :
1.Create/Store plist file inside ~/Library/LaunchAgents Folder
Plist Example :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>Your_app_plist_name</string>
<key>WatchPaths</key>
<array>
    <string>/Applications/AppName.app/Contents</string>
</array>
<key>EnableGlobbing</key>
<true/>
<key>ProgramArguments</key>
<array>
         <string>osascript</string>
    <string>~/Library/Your_Script.applescript</string>
</array>
<key>OnDemand</key>
<true/>
</dict>
</plist>

Use of this plist file : this plist file start running as soon as you start your mac and any point of time your defined Application chafes or Moved to Trash it will monitor it & will call defined Apple Script


2.Create Apple Script
Create Apple Script is very simple step just goto Apple Script Editor and give same command which you use to run using Terminal .
Apple Script Example :
tell application "Finder"
     do shell script "rm -rf Path of Folder/File"
end tell

So , whenever your Application move to Trash Plist file will run & call Apple Script which you define in your plist file . Script will run command for example you are removing any folder.