dustinjb
dustinjb

Reputation: 29

Apple Script to delete file

I'm trying to write an applescript to delete my sleepimage file. The terminal command to do

sudo rm /private/var/vm/sleepimage

Clearly I cannot just type that into the applescript editor, so I've been using this

do shell script rm / private / var / vm / sleepimage with administrator privileges

But with that I get this error

error "The variable rm is not defined." number -2753 from "rm"

Any help would be appreciated, I know its simple, but I'm not too good with this code stuff.

Thank you!

Upvotes: 1

Views: 3545

Answers (3)

adayzdone
adayzdone

Reputation: 11238

Try:

set myPath to "/private/var/vm/sleepimage"
set usr to "username"
set pswd to "password"

do shell script "rm " & quoted form of myPath user name usr password pswd with administrator privileges

Upvotes: 0

Anya Shenanigans
Anya Shenanigans

Reputation: 94614

The more sensible solution is to do:

sudo pmset hibernatefile /dev/null

Then once you delete the hibernate file once, it is deleted for good.

Upvotes: 0

Michael Dautermann
Michael Dautermann

Reputation: 89509

I suspect you just need some quotes in your miniature Applescript there.

try:

do shell script "rm /private/var/vm/sleepimage" with administrator privileges

I'll be amazed if this is what you end up using in the end though, because it's going to require you (or somebody) to type in the admin username & password each time that script is called.

Upvotes: 1

Related Questions