Uninstaller

I’m working on an uninstaller and need some help
Here’s My Code:

on clicked theObject
tell window “Main”
set theApp to string value of text field “Text”
move theApp to trash

end tell

end clicked

Model: iMac
AppleScript: 2.2.1
Browser: Safari 525.20.1
Operating System: Mac OS X (10.5)

Hi,

only the Finder can move files to trash, and the parameter must be an alias or a string path with syntax


tell application "Finder"
	move file theApp to trash
end tell

Now I’m Getting an error Message that says "Finder Got an error: Can’t Get File “FileMaker Pro 3.0”. (-1728)
Here’s My Code:

on clicked theObject
tell window “Main”
set theApp to string value of text field “Text”
end tell
tell application “Finder”

	move file theApp to trash
end tell

end clicked

It Would Be Great If you could Help

Charlie

the value of the text field must be the full HFS path to the application

How Can I Make It So That You Can Just Enter The Name Of The Application?

Find the application with Spotlight or use my CLI LSFindApp, which identifies the application with LaunchServices

How???

download LSFindApp and add it to your project with Add > Existing Files into the Resources folder.
Don’t forget to check “Copy items into destination group.”
then use some code like


set pathToLSFindApp to quoted form of (POSIX path of (path to me) & "Contents/Resources/LSFindApp")

set theApp to string value of text field "Text" of window "Main"
set appPath to (do shell script pathToLSFindApp & " -path " & quoted form of theApp)
if appPath contains "not found" then
	-- do error handling
else
	set HFSpath to POSIX file appPath as alias
	tell application "Finder" to move HFSpath to trash
end if

How Do I Do it with Spotlight?

something like this


do shell script "/usr/bin/mdfind 'iTunes.app'"

but you have to check, if the string contains the .app extension and you have to determine the proper search result,
because SpotLight finds all items whose name contains iTunes.app.

The LSFindApp solution is much more reliable and much faster

Couldn’t I just say “Set i to path to application theApp.”
Also, I don’t know how to use the LSFindApp in my script.

You can also use path to application “xyz”, but this is the slowest solution

What Do You Mean?

the result of

path to application "iTunes"

is
→ alias "[startvolume]:Applications:iTunes.app

Problems:
if the application is not installed, the script doesn’t compile
if there is more than one application installed, maybe different versions, the script could point to the wrong one

Therefore this method is not very reliable