newbie advice needed on how to tackle this in a script

I am going to try my hand at Applescript to automate a simple task in the lab I administer, but I don’t know enough about Applescript yet to know from what angle I should come at this problem.

I am trying to make a script that runs every few minutes and cleans up files on the desktop moving them to the trash.

If Word is not running, it should move all word files to the trash. If Powerpoint is not running, it should move all Powerpoint files to the trash. If Preview is not running, it should move all PDF files to the trash.

Sounds simple, huh? :slight_smile: I read in the FAQ how to find out if the applications are running with something like

tell application “System Events” to (name of processes) contains “someprogram”

and that makes sense. I am having more trouble understanding how to make Finder work with files. Can I make Finder delete all the files of a certain type? That would help make an easy script.

Also, and this is entirely a frosting on the cake sort of thing, can Applescript tell when the screensaver is running and do a cleanup then?

Thanks for any pointers/suggestions!

Heath

In order to manipulate files easily based on file attributes, try employing a ‘whose clause’:

tell application "Finder"
	set word_files to every file of desktop whose kind = "Microsoft Word document"
	delete word_files
end tell

To run scripts during a screen saver, you’ll need to seek out an add-on like Scenario (Here: http://www.versiontracker.com/dyn/moreinfo/macosx/21086)