Help with applescript

Hi,

Im new to applescript and wondering if you guys can help me.

What im trying to do is delete ALL files from the desktop and trash can of a certain user in OSX 10.4

I can do this in the terminal but every time i try and put it into applescript i get lost!

Heres the commands i use in terminal:

[code]cd /Users/user1/Desktop
rm .

cd /Users/user1/.Trash
rmdir *[/code]
This works fine in terminal, i would like to put in to applescript and have it run at login.

cheers

Although I would stay away from a rm . or rmdir * like the plague, these might be what you want:

do shell script "rm /Users/user1/desktop/*.*"

do shell script "rmdir /Users/user1/.Trash/*"

hi dgor,

you didn’t post it, but i think you need to be root or use sudo to have those scripts run properly. i think your best bet would be to create a, ‘loginhook’ as specified on this page:

http://www.bombich.com/mactips/loginhooks.html

see if that doesn’t work better for you.

Ive had a go at that loginhook and was unable to make it work.

Ive changed the scripts round abit now and have 4 seperate ones.

One each for the users desktop files, folders, trashed files and trashed folders.

Although if there is no files or folders to be deleted it displays an error with and ok button.

Is there a way to tell the script to click that ok button if it’s displayed?

Heres my script so far


do shell script "rm /Users/user/desktop/*.*"


do shell script "rm /Users/user/.Trash/*.*"


do shell script "rmdir /Users/user/desktop/*"


do shell script "rmdir /Users/user/.Trash/*"

The reason im using /* and . is that the users should save all there work to the network store and i would like the systems to be clean and tidy.

Cheers again

Try this:

try
	
-- note that you can separate scripts using semicolons.
	do shell script "rm /Users/user/desktop/*.*; rm /Users/user/.Trash/*.*; rmdir /Users/user/desktop/*; rmdir /Users/user/.Trash/*"
	
on error -- do nothing
	
end try

Thanks for that, works a charm :smiley:

i just thought i would comment on this, wouldnt it be easier to have a cron job that ran a simple bash script every 24 hours to do those cmds?