I administrate several labs. I am learning AppleScript & have had some success w/ several simple scripts.
But this one is puzzling. I wish to have a script run at login for the user “art” that will delete all items from Desktop except the STARTUP & WORKSPACE partitions (named identically on each wkstn).
Could someone point me in the right direction to solve this?
Thanks, -Barry
pai:
The Desktop is a folder, like any other folder, and your Hard Drive partitions should be safe from deletion using something like this:
tell application "Finder"
try
delete every file of entire contents of desktop
end try
try
delete (every folder of entire contents of desktop whose name is not in {"STARTUP", "WORKSPACE"})
end try
end tell
Good luck,
Edit: I tested this on a spare User Desktop on my machine, and it worked fine with my Hard Drive name in the list. I put each command in a try block because it chokes if there are only files or only folders on the Desktop.
Hi Barry,
Create one application using applescript as code given by Smith and put this application as login item for the user. As user will login this script will get executed and remove all the files from the desktop.
tell application "Finder"
try
delete every file of entire contents of desktop
end try
try
delete (every folder of entire contents of desktop whose name is not in {"STARTUP", "WORKSPACE"})
end try
empty trash
end tell
Please let me know if you need another help.
Thanks
Rajeev
I have gotten the script below to work. However, it seems to stop if & when the student has connected an external drive. In such case, there is no way to know the drive name to create an exception. IS there a workaround?
tell application “Finder”
try
delete every file of entire contents of folder “Desktop” of folder “art” of folder “Users” of startup disk
end try
try
delete (every folder of entire contents of desktop whose name is not in {“STARTUP”, “WORKSPACE”})
end try
empty trash
end tell
Thanks, -barry
Try this, it should take care of the partitions ,dmg’s and external drives.
This worked on a test desktop.
I will say test and use any delete action very, very carefully.
set exepction_disk_list to list disks
tell application "Finder"
try
delete every file of entire contents of desktop
end try
try
delete (every folder of entire contents of desktop whose name is not in exepction_disk_list)
end try
empty trash
end tell
Volia! Works like a charm. Thank you!