App to run once and delete itself

Is it possible to make a script (.app) delete itself? I’ve played with a couple of things but I’m thinking you can’t do it because in order for it to delete itself the app would have to be closed. Any thoughts?

Maybe someone can elaborate on this, but you could add this to the end of your script:

do shell script "rm -rf pathtoapp > /dev/null 2>&1 &"

This will run the shell command “remove” in paralell with your AppleScript, so when you Script completes, the shell command will delete it.

I’m sure this needs tweaking, so maybe someone can elaborate.

at the end of script one, maybe put

open file "Path to:script2"

and then make Script 2 on a networkable server … have it delete script 1.

Not too elegant, I’ll admit. But it might work.

I couldn’t get the delete command to work, but after some playing around, I got the move command to do its thing:

tell application "Finder"
        move (application file of application process "Your Applet Name" as alias) to trash
end tell

Beware, it takes slow-poke Mr. OS X several seconds to update the appearance of the trashcan.
Hey, does anyone remember back when the Mac was a lean, fast, modern computer system? :slight_smile:

Thanks for the suggestions, I appreciate it. I can’t seem to get any of these to work. Has anyone tested any of these successfully?

Yes, I tested my solution before posting. Are you on Panther?

Yea I’m on panther. I think maybe I’m confused by “application file of application process” Can you give an example? Thanks.

They’re in the Finder dictionary. Just open a new script document with this text:

tell application "Finder" 
  move (application file of application process "My Script" as alias) to trash 
end tell

Then save the script as an application with the name “My Script”. Go to the Finder and double-click on the applet, it should move its file to the trash and quit. Like I mentioned, it can take a surprising number of seconds for the trashcan to “realize” that it now has the script file in its contents, but it works.

If you’re still having problems, you can send your script to me at:

a r t h u r @ s t e l l a r v i s i o n s . c o m

If you do, please send it as “text,” and not as a compiled script, (I may not have the applications that you are trying to script, but I may not need them to help you).

Cool, that worked. I’m not sure why it didn’t work the first time because that’s exactly what I did. I think I added the .app which is why it didn’t work. Thanks for your help.