This script used to work before 10.3.9

I made this scrip a long time ago and use(d) it often to get rid of dektop clutter. Unfotunately, since I upgraded to OS 10.3.9 I get errors and I can’t figure out the new syntax to use to correct the problems. When I correct one problem another arrises at another point in the script. If someone can help me update this script to work with OS 10.3.9 I would truly appreciatethe help. Thanks in advance.
-G


property thisList : {}
property date_n_time : ""
dateTimeGetter()

tell application "Finder"
	set dt to (desktop) as string
	set the_files to every file of folder dt
	try
		make new folder at startup disk with properties {name:"Cleanup"}
	end try
	try
		make new folder at desktop with properties {name:date_n_time}
	end try
end tell

set desktopPath to path to desktop
set these_items to list folder desktopPath
tell application "Finder"
	repeat with i from 1 to the count of these_items
		set this_item_name to item i of these_items
		set this_item to (desktopPath as string) ¬
			& this_item_name as alias
		
		if (class of this_item is not disk) ¬
			and (the first character of this_item_name ¬
			is not ".") then
			set name_extension to (name extension of (info for this_item))
			tell application "Finder"
				if name_extension is in {"mov", "mpg", "avi", "wmv", "MPG", "mpeg", "moov"} then
					try
						make new folder at folder date_n_time with properties {name:"Movies"}
					end try
					move this_item to folder "Movies" of folder date_n_time of desktop
				else if name_extension is in {"jpg", "jpeg", "png", "gif", "bmp", "pdf", "tif", "art", "pic", "pict", "pictureClipping"} then
					try
						make new folder at folder date_n_time with properties {name:"Pictures"}
					end try
					move this_item to folder "Pictures" of folder date_n_time of desktop
				else if name_extension is in {"mp3", "wav", "mp4", "mid", "aif", "aiff"} then
					try
						make new folder at folder date_n_time with properties {name:"MusicAndSound"}
					end try
					move this_item to folder "MusicAndSound" of folder date_n_time of desktop
				else if name_extension is in {"textClipping", "text", "html", "htm", "js"} then
					try
						make new folder at folder date_n_time with properties {name:"Text"}
					end try
					move this_item to folder "Text" of folder date_n_time of desktop
				else
					set theKind to (kind of (info for this_item))
					if theKind is not "folder" then
						move this_item to folder date_n_time of desktop
					end if
				end if
			end tell
		end if
	end repeat
	tell application "Finder"
		if the_files ≠ {} then
			try
				move folder date_n_time to folder "Cleanup" of startup disk
			end try
		else
			move folder date_n_time to trash
		end if
	end tell
	
end tell

to dateTimeGetter()
	tell application "Finder"
		set cd to (current date) as string
		set theDay to item 1 in cd & item 2 in cd & item 3 in cd as string
		(*set d1 to item 1 in cd
		set d2 to item 2 in cd
		set d3 to item 3 in cd*)
		set m to (month of (current date) as integer)
		if m < 10 then (*create leading zero for month*)
			set m to "0" & m
		end if
		set d to day of (current date)
		if d < 10 then (*create leading zero for day*)
			set d to "0" & d
		end if
		set yod to year of (current date) as string
		set y to count of items in yod
		set c to count of items in cd
		if item (c - 10) in cd is " " then (*create leading zero for hour*)
			set c10 to 0
		else
			set c10 to 1
		end if
		set c9 to item (c - 9) in cd
		if item (c - 10) in cd is equal to "1" and item (c - 9) in cd is equal to "2" then
			set c10 to 0
			set c9 to 0
		end if
		set date_n_time to m & "/" & d & item (c - 1) in cd & item c in cd & c10 & c9 & "/" & item (c - 7) in cd & item (c - 6) in cd & "/" & item (c - 4) in cd & item (c - 3) in cd & theDay as string
	end tell
	log c10
	log c9
end dateTimeGetter

Model: iMac
AppleScript: 1.9.3
Browser: Safari 312.6
Operating System: Mac OS X (10.3.9)

You might be interested to know that this script works perfectly in Tiger, AS 1.10.7, which is all I have to test it with.

Well, I guess that’s a good thing.
I can’t afford to get Tiger right now because I think I’d have to upgrade my Mac to keep it from slowing down.
Hopefully, someone running the same OS with more Applescript knowledge than myself will know what changes need to be made to get this thing running correctly again.
Thanks much for testing it and the reply.
-G

Hi, gasp.

When asking questions like that, it would help if you said what isn’t working, what the errors are, and what it should do when it is working. :slight_smile:

I can’t see why the main part of the script shouldn’t work. But it does mix aliases and Finder references quite a lot, so maybe 10.3.9 is sensitive to that. I’ve done a version below ” based on what I think is supposed to happen ” that doesn’t use aliases.

Your dateTimeGetter() handler relies heavily on the Date & Time preferences on your own machine. I’d guess your long date format is in English, starting with the weekday, and ending with the time in 12-hour format and with no leading zero on the hour. It also seems from your code that you want both 12 am and 12 pm rendered as “00” in the output string, which should otherwise look something like this: “07/19am10/39/02Wed”.

If I’m right so far, this should work for you:

set date_n_time to dateTimeGetter()

tell application "Finder"
	if (count desktop each file) > 0 then
		try
			set dntFolder to (make new folder at desktop with properties {name:date_n_time})
		on error
			set dntFolder to folder date_n_time of desktop
		end try
		
		my fileUnder({"mov", "mpg", "avi", "wmv", "MPG", "mpeg", "moov"}, "Movies", dntFolder)
		my fileUnder({"jpg", "jpeg", "png", "gif", "bmp", "pdf", "tif", "art", "pic", "pict", "pictureClipping"}, "Pictures", dntFolder)
		my fileUnder({"mp3", "wav", "mp4", "mid", "aif", "aiff"}, "MusicAndSound", dntFolder)
		my fileUnder({"textClipping", "text", "html", "htm", "js"}, "Text", dntFolder)
		move files of desktop to dntFolder
		
		try
			make new folder at startup disk with properties {name:"Cleanup"}
		end try
		try
			move dntFolder to folder "Cleanup" of startup disk
		end try
	end if
end tell

to dateTimeGetter()
	set {w, d, m, y, t} to {weekday, day, month, year, time} of (current date)
	
	set w to text 1 thru 3 of (w as string)
	set m to text 2 thru 3 of ((100 + m) as string)
	set d to text 2 thru 3 of ((100 + d) as string)
	if t div hours < 12 then
		set x to "am"
	else
		set x to "pm"
	end if
	set hr to text 2 thru 3 of ((100 + t div hours mod 12) as string)
	set min to text 2 thru 3 of ((100 + t mod hours div minutes) as string)
	set sec to text 2 thru 3 of ((100 + t mod minutes) as string)
	
	return m & "/" & d & x & hr & "/" & min & "/" & sec & w
end dateTimeGetter

on fileUnder(extensionList, folderName, dntFolder)
	tell application "Finder"
		set these_items to files of desktop whose name extension is in extensionList
		if these_items is not {} then
			try
				make new folder at dntFolder with properties {name:folderName}
			end try
			move these_items to folder folderName of dntFolder
		end if
	end tell
end fileUnder

Some people reckon that in OS X, you shouldn’t use the slash character (“/”) in file or folder names, because that’s the name separator in Unix paths. I don’t think it’s as fatal as people like to make out, but many applications won’t let you use it.

Sorry for not giving more details about the error in my script.
I’m getting the exact error message in your version also. I made notations in the script so you can see where the problem is.


set date_n_time to dateTimeGetter()

tell application "Finder"
	if (count desktop each file) > 0 then
		try
			set dntFolder to (make new folder at desktop with properties {name:date_n_time})
		on error
			set dntFolder to folder date_n_time of desktop
		end try
		
		my fileUnder({"mov", "mpg", "avi", "wmv", "MPG", "mpeg", "moov"}, "Movies", dntFolder)
		my fileUnder({"jpg", "jpeg", "png", "gif", "bmp", "pdf", "tif", "art", "pic", "pict", "pictureClipping"}, "Pictures", dntFolder)
		my fileUnder({"mp3", "wav", "mp4", "mid", "aif", "aiff"}, "MusicAndSound", dntFolder)
		my fileUnder({"textClipping", "text", "html", "htm", "js"}, "Text", dntFolder)
		move files of desktop to dntFolder
		
		try
			make new folder at startup disk with properties {name:"Cleanup"}
		end try
		try
			move dntFolder to folder "Cleanup" of startup disk
		end try
	end if
end tell

to dateTimeGetter()
	set {w, d, m, y, t} to {weekday, day, month, year, time} of (current date)
	
	set w to text 1 thru 3 of (w as string)
	set m to text 2 thru 3 of ((100 + m) as string)
	set d to text 2 thru 3 of ((100 + d) as string)
	if t div hours < 12 then
		set x to "am"
	else
		set x to "pm"
	end if
	set hr to text 2 thru 3 of ((100 + t div hours mod 12) as string)
	set min to text 2 thru 3 of ((100 + t mod hours div minutes) as string)
	set sec to text 2 thru 3 of ((100 + t mod minutes) as string)
	
	return m & "/" & d & x & hr & "/" & min & "/" & sec & w
end dateTimeGetter

on fileUnder(extensionList, folderName, dntFolder)
	tell application "Finder"
		set these_items to files of desktop whose name extension is in extensionList
		if these_items is not {} then
			try
				make new folder at dntFolder with properties {name:folderName}
			end try
--*************************************************************
			--Script Editor highlights the following line as an error...
			move these_items to folder folderName of dntFolder
			--The error dialog box says...
			--Finder got an error.  Can't get (document file "name of file 1.jpg" of desktop, 
			--document file "name of file 2.txt" of desktop, document file "name of file 3.mpg" of desktop)
--*************************************************************
		end if
	end tell
end fileUnder

Model: iMac
AppleScript: 1.9.3
Browser: Safari 312.6
Operating System: Mac OS X (10.3.9)

Thanks to all who replied to my post and attempted to help me out.
I figured out the problem, although I still don’t understand why it happens.
I had FileVault turned on in my security preferences. When I turned off FileVault the script runs perfectly.
I wonder if there’s a way to create this script and have it work with FileVault on? I doubt it.
Maybe someone else with the same type of problem will read this thread and save themselves a lot of confusion.
Thanks again
-G

You might like to take a look at FileVault-proof Finder selection to alias list, gasp. (I don’t use FileVault, and therefore haven’t tested the script ” although it should help to solve at least the initial part of the problem.)

To move the files, your best bet might be to use (part of) the script to extract their POSIX paths ” and then apply the mv command to them.

In case you’re not sure how to go about the latter, this simple example might help:

set f to quoted form of POSIX path of (choose file without invisibles)
set t to quoted form of POSIX path of (choose folder)
do shell script "/bin/mv -n " & f & space & t

If, after looking at this kind of approach, you still need further help - just ask. :slight_smile: