When I have uninstalled my application, using the Applescript utility I created, it works fine. However, when double-clicking my script again, it doesn’t launch the script editor, instead, it launches a window stating that the application I had uninstalled was not found and it needed it. Oddly, when I re-install that application, I can now double-click my script to edit my code…that’s weird. Why is that?
AppleScripts like to be compiled. On launch, I assume that your script is trying to compile itself, and when a script compiles it looks for, among other things, every application that you have stated and, if it isn’t found, asks you to find it. This feature I assume is designed so that if you have a long piece of code with the name of one applicaiton spelled wrong, you don’t have to go hunting for it (obviously you can’t search-and-replace, because it’s misspelled. The short answer is that yes, it does need the application, and it want’s you to find it for it. If that didn’t make sense, read it again.
Your solution to this would be to
A) click cancel on this dialog and, if i’m right, watch your script open uncompiled or
B) Convert it into a droplet, something like:
on open theseItems
tell application thisItem
quit
end tell
delete thisItem
end open
This should quit and then delete any application you drop onto it. It compiles, but I have not tested it, and I assume that dropping anything other than an application would produce an error. If that were not the case, the item would be deleted. To correct this, it should become
on open theseItems
set appName to name of thisItem
if nameExtention of thisItem is "app" then
set continueDelete to (display dialog "Are you sure you want to quit and delete " & appName & "?" buttons {"Yes", "No"} default button 2)
if button returned of continueDelete is "Yes" then
tell application thisItem
quit
end tell
delete thisItem
end if
else
display dialog thisItem & "is not an application." buttons {"OK"} default button 1
end if
end open
Does that work?
Edit: I wasn’t clear on this… the script needs to be saved as an application/application bundle to work (I recommend Application Bundle- it’s universal), and running it from Script Editor will do absolutely nothing. You need to drop the file (or files, if you want to add a repeat to it) you want to delete onto the application, which should have this symbol: [url=http://www.vandogar.com/wp-content/uploads/2007/04/applescript_icon.png]http://www.vandogar.com/wp-content/uploads/2007/04/applescript_icon.png[/url]
on open thisItem
if (count of thisItem) > 1 then
display dialog "Only one item at a time." buttons {"OK"}
return
end if
--name and name extension are both part of the "info for" command
set {appName, nameExtention} to {name, name extension} of (info for thisItem)
if nameExtention is "app" then
set continueDelete to (display dialog "Are you sure you want to quit and delete " & return & appName & " ?" buttons {"Yes", "No"} default button 2)
if button returned of continueDelete is "Yes" then
--you will get an error if you try to quit an app that is not
--running so put it in a try block or you could check to
--see if the app is running first
try
tell application thisItem to quit
end try
--to "delete" an item, move it to the trash
--you can then empty trash
tell application "Finder" to move thisItem to the trash
end if
else
display dialog appName & " is not an application." buttons {"OK"} default button 1
end if
end open