move some items off desktop but not others

Like it says on the tin, Im trying to create a clean up script that clears off desktop clutter but leaves a few files, aliases and directories behind. I can get the following to work whole cloth - but I cant quite figure out how to omit a list of file and folder names, such as {“DropBox alias”, “App alias”, “folderX”, “file3”} etc. Im sure this has been covered elsewhere but I’ve spent quite a bit of time searching this and other forums and I just cant peg it.

Any help would be greatly appreciated.


set foldername to ("Desktop " & short date string of (current date) & time of (current date))
set docsfolder to (path to documents folder) as string

tell application "Finder"
	if not (exists folder (docsfolder & foldername)) then
		make new folder at docsfolder with properties {name:foldername}
	end if
	move items of (path to desktop folder) to folder (docsfolder & foldername)
end tell

Hi,

try this


property exclusionList : {"DropBox alias", "App alias", "folderX", "file3"}

tell (current date) to set foldername to ("Desktop " & its short date string & its time)
set currentCleanupFolder to (path to documents folder as text) & foldername
do shell script "/bin/mkdir -p " & quoted form of POSIX path of currentCleanupFolder

tell application "Finder"
	move (get items of desktop whose class is not disk and name is not in exclusionList) to folder currentCleanupFolder
end tell

Stefan - thanks so much.

This is what I ended up with - I added a little logic to prevent unnecessary directories being made. Perhaps someone knows - could this cause problems if a user leaves a file open in an application and then this script moves it? I was planning to automate this script to fire at 1am so Im not expecting to clash there, but students leave open apps all the time.

property exclusionList : {"some alias", "somefile", "someDir"}

tell application "Finder"
	set itemList to count (get items of desktop whose class is not disk and name is in exclusionList)
	set allFiles to count (get items of desktop whose class is not disk)

	if itemList < allFiles then
		set foldername to ("Desktop " & ((do shell script "date '+%Y%m%d%H%M%S'") as text))
		set currentCleanupFolder to (path to documents folder as text) & foldername
		do shell script "/bin/mkdir -p " & quoted form of POSIX path of currentCleanupFolder
		set desktopclutter to (get items of desktop whose class is not disk and name is not in exclusionList)
		move (get items of desktop whose class is not disk and name is not in exclusionList) to folder currentCleanupFolder
	end if
end tell