random happenings with "on adding folder items to"

Hi guys,

I’m having trouble with the “on adding folder items to” command

With the script below if I comment out the “on adding” and “end adding” lines it works perfectly but if I keep the lines in and attach the script to a folder it gets as far as making a contact sheet in photoshop but then stops.

Any ideas why? I would be slightly less confused if it just didn’t work but why it works just to a certain point I don’t understand.

Thanks,
JM


--on adding folder items to this_folder
	tell application "Finder"
		if (count files in folder "photo" of desktop) = 4 then
			tell application "Finder"
				activate
				set theDate to (current date)
				copy theDate to b
				set the month of b to January
				set monthNum to (1 + (theDate - b + 1314864) div 2629728)
				if (monthNum < 10) then
					set monthNum to "0" & (monthNum as string)
				end if
				set yearNum to the year of theDate
				set dateNum to the day of theDate
				if (dateNum < 10) then
					set dateNum to "0" & dateNum
				end if
				set hourNum to the hours of theDate
				if (hourNum < 10) then
					set hourNum to "0" & hourNum
				end if
				set minuteNum to the minutes of theDate
				if (minuteNum < 10) then
					set minuteNum to "0" & minuteNum
				end if
				set secondNum to the seconds of theDate
				if (secondNum < 10) then
					set secondNum to "0" & secondNum
				end if
				set theFileName to (yearNum as string) & "-" & (monthNum as string) & "-" & (dateNum as string) & "-" & (hourNum as string) & "-" & (minuteNum as string) & "-" & (secondNum as string) & ".psd"
				set theFolderName to (yearNum as string) & "-" & (monthNum as string) & "-" & (dateNum as string) & "-" & (hourNum as string) & "-" & (minuteNum as string) & "-" & (secondNum as string)
				set newfolder to make new folder at "Macintosh HD:Users:jean:Desktop:backup:" with properties {name:theFolderName}
			end tell
			tell application "Finder"
		activate
		move (every item of folder "Macintosh HD:Users:jean:Desktop:photo:") to folder theFolderName of folder "backup" of desktop
		set theFiles to files of folder (theFolderName as text) of folder "backup" as alias list
	end tell
	tell application "Adobe Photoshop"
		activate
		creat contact sheet from files thefiles with options {resolution:346, width:1281, height:1904, column count:2, row count:2, autospacing:false, caption:false, horizontal offset:23, vertical offset:36}
		resize image current document width 9.4.4 height 13.9777
		do action "photo" from "Default Actions.atn"
		purge all caches
				set myFile to (newfolder as text) & (theFileName)
		set myOptions to {class:photoshop save options, embed color profile:true, save spot colors:true, save alpha channels:true, save annotations:true, save layers:true}
		save current document in file myfile as Photoshop format with options myoptions appending no extension without copying
		close current document saving no
			end tell
			end if
	end tell
--end adding folder items to

Hi

I have had some very odd problems with folder actions and found them to be unreliable. Whenever possible I use an idle handler or a run script command.

I have also had some weird stuff happening when scripting photoshop CS3. Scripts that would work one day would not work the next and so on. I now use a mixture of “hard coding” and calling actions within photoshop.

I enclose a date handler that was posted to me from (sorry, forgot) which could cut down some of your work.


set x to date_format(current date)
on date_format(old_date)
	set {year:y, month:m, day:d, time:t} to old_date
	tell (y * 10000 + m * 100 + d) as string to set date_part to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8
	if (t < 12 * hours) then
		set suffix to " AM"
	else
		set suffix to " PM"
	end if
	tell (1000000 + ((t div hours + 11) mod 12 + 1) * 10000 + t mod hours div minutes * 100 + t mod minutes mod 100) as string to ¬
		set time_part to text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7 & suffix
	
	return date_part & " " & time_part
end date_format


Model: Lots of them
Browser: Safari 523.15
Operating System: Mac OS X (10.5)