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
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
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
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 =)
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
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