problem with date in script

this script selects and moves files in folders it makes and places on server…has worked fine except this month…i changed the date on my system to trouble shoot this and the script works fine…but for the life of me i can’t figure why. A very nice friend wrote it for me and i d’ appreciate any input…maybe to make it faster? Maybe a shell script to do similiar.

Background on this is I use Eudora to drag attachments and email to desktop: select thos files on desktop then run this script after copying the domain name from emails “from” field. This script saves me tons of time and makes my arms not hurt :slight_smile:
TIA, KC


tell application "Finder"
	activate
	try
		set RootFolder to folder "!preflight_art" of folder "Art Dept" of disk "TAZ.VOL1"
		
		set theFoldername to the clipboard
		if length of theFoldername > 30 then set theFoldername to text 1 thru 30 of theFoldername
		
		copy ((offset of (the month of (current date)) in "jan feb mar apr may jun jul aug sep oct nov dec ") + 3) / 4 as integer to mo
		if mo < 10 then copy "0" & mo as string to mo
		copy day of (current date) to da
		if (day of (current date) < 10) then copy "0" & da as string to da
		copy mo & "_" & da & "_" & (year of (current date) as string) to shortDate
		
		if not (exists folder shortDate of RootFolder) then make new folder at RootFolder with properties {name:shortDate}
		
		set TheDateFolder to folder shortDate of RootFolder
		
		if not (exists folder theFoldername of TheDateFolder) then make new folder at TheDateFolder with properties {name:theFoldername}
		
		set TheFinalFolder to folder theFoldername of TheDateFolder
		
		set CountFolder to 1
		repeat
			if not (exists folder (CountFolder as string) of TheFinalFolder) then
				exit repeat
			else
				set CountFolder to CountFolder + 1
			end if
		end repeat
		
		set CountFolder to CountFolder as string
		if not (exists folder CountFolder) then
			make new folder with properties {name:CountFolder}
		end if
		if not (exists folder "orig") then
			make new folder with properties {name:"orig"}
		end if
		beep
		move the selection to folder "orig"
		beep 2
		move folder "orig" to folder CountFolder
		move folder CountFolder to TheFinalFolder
		move folder CountFolder to trash
	on error
		display dialog "G'day KC/Could be worse could be using a PC: " & return & return & TheError
	end try
	
	tell application "TextEdit" to quit
	
end tell

and here’s the event log:

tell application “Finder”
activate
get folder “!preflight_art” of folder “Art Dept” of disk “TAZ.VOL1”
folder “!Preflight_Art” of folder “Art Dept” of disk “TAZ.VOL1”
the clipboard
nationalenvelope.com
current date
date “Tuesday, October 2, 2007 7:21:33 AM”
offset of October in "jan feb mar apr may jun jul aug sep oct nov dec "
37
current date
date “Tuesday, October 2, 2007 7:21:33 AM”
current date
date “Tuesday, October 2, 2007 7:21:33 AM”
current date
date “Tuesday, October 2, 2007 7:21:33 AM”
exists folder {10, “", “02”, "”, “2007”} of folder “!Preflight_Art” of folder “Art Dept” of disk “TAZ.VOL1”
“The variable TheError is not defined.”

Model: g5 dual Intel
Browser: Safari 522.12.1
Operating System: Mac OS X (10.4)

Hi Kevin,

in your creation of the date format you’re copying integer and string values, so AppleScript
interprets them as a list instead of concatenting the values.
The date string can be created with this one-liner

tell ((current date) as «class isot» as string) to set shortDate to text 6 thru 7 & "_" & text 9 thru 10 & "_" & text 1 thru 4

and you should define the error variable

 on error theError
       display dialog "G'day KC/Could be worse could be using a PC: " & return & return & TheError
 end try

Script works great AND a little faster too!

final script:

tell application "Finder"
	activate
	try
		set RootFolder to folder "!preflight_art" of folder "Art Dept" of disk "TAZ.VOL1"
		
		set theFoldername to the clipboard
		if length of theFoldername > 30 then set theFoldername to text 1 thru 30 of theFoldername
		
		tell ((current date) as «class isot» as string) to set shortDate to text 6 thru 7 & "_" & text 9 thru 10 & "_" & text 1 thru 4
		
		
		if not (exists folder shortDate of RootFolder) then make new folder at RootFolder with properties {name:shortDate}
		
		set TheDateFolder to folder shortDate of RootFolder
		
		if not (exists folder theFoldername of TheDateFolder) then make new folder at TheDateFolder with properties {name:theFoldername}
		
		set TheFinalFolder to folder theFoldername of TheDateFolder
		
		set CountFolder to 1
		repeat
			if not (exists folder (CountFolder as string) of TheFinalFolder) then
				exit repeat
			else
				set CountFolder to CountFolder + 1
			end if
		end repeat
		
		set CountFolder to CountFolder as string
		if not (exists folder CountFolder) then
			make new folder with properties {name:CountFolder}
		end if
		if not (exists folder "orig") then
			make new folder with properties {name:"orig"}
		end if
		beep
		move the selection to folder "orig"
		beep 2
		move folder "orig" to folder CountFolder
		move folder CountFolder to TheFinalFolder
		move folder CountFolder to trash
	on error
		display dialog "G'day KC/Could be worse could be using a PC: " & return & return & TheError
	end try
	
	tell application "TextEdit" to quit
	
end tell