Different HD Names

Hi, I have this script that cleans files off the desktop of the iMacs (OS X 10.2.8) in the lab where I work. A tech from another shool wants to use the same script to clean her computers off. Her hard drive has a different name and maybe each of her iMacs have a different name. Is there a way to make it so that it will work without the actual name of the hard drive and user?

set myFolder to ("Mac HD:Users:middel:Desktop")

tell application "Finder"
	delete (folders of folder myFolder whose name contains "untitled")
	delete (files of folder myFolder)
	empty trash
end tell

l

Thanks,
Connie

Hi Connie,

this is quite easy

set myFolder to path to desktop -- desktop of current user of startup disk

tell application "Finder"
	delete (folders of myFolder whose name contains "untitled")
	delete (files of myFolder)
	empty trash
end tell

And, if for some reason you want to know the name of the disks (volumes) on a machine’s HD:

tell application "Finder" to set V to name of disks

Adam, there is a “shortcut” for it :wink:

set V to list disks

Which I always forget to use. Old dog, new tricks problem… :lol:

Thank you very much :slight_smile:

What if there is a folder on the desktop and I want to delete the contents out of it? How do I add that to the desktop part?

I tried this and it didn’t work.

set myFolder to path to desktop:Student Programs

tell application "Finder"
	delete (folders of folder myFolder whose name contains "untitled")
	delete (files of folder myFolder)
	empty trash
end tell

Thanks :slight_smile:

Try something like this: (General solution)

set myFolder to ((path to desktop as Unicode text) & "Student Programs:")

Alternatively: (Script specific [Untested because I’m not on a Mac right now])

tell application "Finder"
	tell folder "Student Programs" of desktop
		delete folders whose name contains "untitled"
		delete files
	end tell

	empty trash
end tell

Neither of those worked for me. Thank you though :slight_smile:

Hi Connie. Good to hear from you again. :slight_smile:

This works here in both Mac OS 9 and Tiger - so it should work for the intervening OS versions, too:


tell application "Finder"
	tell folder "Student Programs" to delete (folders whose name starts with "untitled") & files
	empty
end tell


Edit: Incidentally, Bruce’s last suggestion works here. As a matter of interest, how does it fail on your machine? Do you get an error message?

Hi =) I finally have time to work on some things that I didn’t finish this summer. So I am back for more =)

You are right. All the scripts that were posted worked. I messed up on the folder name on my desktop and kept getting an error.

Thanks for all the help!

Connie

Okay, as I am playing with these scripts, I think… wouldn’t it be nice to combine them? Sometimes I need just one of them and sometimes I could use all three together. Only thing that I have a problem with is keeping some folders on the desktop that I need. I combined the two scripts here and added folders to be deleted along with files. Only thing is that on the desktop I want to keep the folders Student Projects, Student Programs, and Teacher ESheets and delete all the other folders and files. I searched through the forum, but I couldn’t find how to do it. I am sure that I didn’t type in the right words to find it.

Here is what I have -

set myFolder to path to desktop

tell application "Finder"
	tell folder "Student Projects" to delete (folders whose name starts with "untitled") & files & folders
	delete (folders of myFolder whose name contains "untitled")
	delete (files of myFolder)
	empty
end tell

I know this is easy stuff for you all, so I appreciate all the help you give me and that you don’t give me a hard time about asking the easy stuff =)

this does the job :wink:

set myFolder to path to desktop

tell application "Finder"
	tell folder "Student Projects" to delete (folders whose name starts with "untitled") & files & folders
	delete (folders of myFolder whose name is not in {"Student Projects", "Student Programs", "Teacher ESheet"})
	delete files of myFolder
	empty
end tell

Awesome!!! Thanks so much! :smiley:

Ah, Connie ” that brings to mind a couple of little planks of fundamental philosophy:

Perhaps I could just add that the point of my earlier suggestion was that the desktop is Finder’s default target. So, when working with Finder on the desktop, there’s no need to specify a path; something like this should suffice:


tell application "Finder"
	tell folder "Student Projects" to delete (folders whose name starts with "untitled") & files
	delete (folders whose name is not in {"Student Projects", "Student Programs", "Teacher ESheet"}) & files
	empty
end tell


:slight_smile:

Thanks =)