Delete an app from within an App

I have an app that is downloaded occasionally for our users. It’s always downloaded into /tmp, as it’s a place that doesn’t need any specific permissions to do so

Anyway: I’d like the app to clean up after itself when it terminates: Is there any good practise to do this? Perhaps a do shell script that somehow detaches? Answers on a postcard please!

(This is an Xcode app written in AppleScript with smidges of ASOC thrown in)

It should be able to move itself to the trash while running. Or you can just wait until /tmp is cleaned out, which I think happens every few days.

Cheers Shane. Being moved to the trash should work fine

Dammit.

So, I’ve built a small app. Compiled it, moved it to the /tmp folder, but then run it from XCode.

I get:

So, I throw this into Script Editor and it works fine:

Here’s the simple script

tell application "Finder"
	set sourceFolder to POSIX file "/tmp/deletemyself.app/"
	delete sourceFolder # move to trash
end tell

Ideas?

I’s probably balking at POSIX file x rather than x as POSIX file.

But why faff around with Finder when you have a perfectly good file manager:

set theURL to current application's NSBundle's mainBundle()'s bundleURL()
current application's NSFileManager's defaultManager()'s trashItemAtURL:theURL resultingItemURL:(missing value) |error|:(missing value)

Move to trash was great but, given my requirements,

current application's NSFileManager's defaultManager()'s removeItemAtURL:theURL |error|:(missing value)

works much better

Shane, thanks for your help