Photoshop and Graphic converter script

Hi Guys,
I’m in trouble again.
Long story - I have a script for photoshop that upon receiving files from a camera into a folder launches the app and makes a contact sheet from the files, then runs through some actions and then saves the resulting file.
This works perfectly almost all of the time. Unfortunately due to unknown circumtances every now and again I get a corrupt file from the camera which results in photoshop throwing up an error message which stops the whole script process unless I am there to hit “cancel” or “continue”. I need the whole process to run automatically so this isn’t good.

From posting on this site before I have learnt that opening the files in Graphic Converter and then saving them before opening them again in photoshop will solve this problem. Apparently Graphic Converter is better at opening slightly dodgy files? This does seem to be the case so my next step is to write a script that will do this opening and saving of the files in GC before carrying on with my photoshop script.

Here is my photoshop script -


on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		if (count files in folder "receiving" 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:Desktop:backup:" with properties {name:theFolderName}
			end tell
			tell application "Finder"
				activate
				
				set theFiles to files of folder "receiving" as alias list
			end tell
			tell application "Adobe Photoshop CS3"
				activate
				--does it's stuff and then saves the psd file to newfolder
			end tell
			tell application "Finder"
				move (every item of folder "Macintosh HD:Users:Desktop:receiving:") to folder theFolderName of folder "backup" of desktop
			end tell
		end if
	end tell
end adding folder items to

I was assuming that I would be able to do the same sort of “on adding” script for Graphic converter but I’m afraid I can’t work out how to open the files (they will have a different name each time so I can’t be file specific) and then save them again using the same file name. It might be best to save them to a new folder and run the photoshop script from that folder.

In my photoshop script it is making a contact sheet from the available files in the folder therefore I don’t have to tell it which files specifically to open.

I’m sure I’ve lost you all by now but any help would be most appreciated.

JM

Hi,

in my opinion it’s more efficient to catch the error in Photoshop and resave only these images.

PS: I remember having suggested once a clean version of your date grabbing code

Hi Stefan,

You did indeed and I thank you for all the help you’ve given me. For some reason the clean version of the time stamp you gave me threw up some problems later in my script with photoshop actions. I have no idea why so I reverted to my original.

I don’t understand how to catch an error in photoshop so I carried on trying to open the files in Graphic Converter. As you know I’m no programmer so I cobbled together some code from my last script along with other stuff from this site.

on adding folder items to this_folder after receiving theFiles
	tell application "Finder"
		if (count files in folder "GC test" of desktop) = 4 then
			tell application "Finder"
				activate
				try
				repeat with oneitem in theFiles
					set thepath to "macintosh hd:users:semausryan:desktop:GC test receive:"
					set thefile to name of (info for oneitem)
					set aliasfile to oneitem as string
					set the thename to thefile
					tell application "GraphicConverter"
						activate
						open {alias aliasfile}
						tell window 1
							set thispath to "Macintosh HD:users:desktop:GC test receive:"
							
							save in (thispath & thename) as JPEG
							close
						end tell
						tell application "Finder"
							delete theFiles
						end tell
					end tell
					
				end repeat
				
			end tell
		end if
	end tell
end adding folder items to

This nearly works but for some reason will only open, save and close 2 of the files and occasionally 3 but not 4!?

Any thoughts?

JM

You have the delete line within the repeat loop,
that means, you trash the all files after processing the first.

I don’t use GraphicConverter, therefore I can’t test this, but I removed also the nested application tell blocks.
A problem could also be, that you check for the number of files in the folder, but process only the just added ones


on adding folder items to this_folder after receiving theFiles
	set thepath to ((path to desktop as text) & "GC test receive:")
	tell application "Finder" to set CF to (count files in folder "GC test" of desktop)
	if CF = 4 then
		repeat with oneitem in theFiles
			set fileName to name of (info for oneitem)
			tell application "GraphicConverter"
				activate
				open oneitem
				tell window 1
					save in (thepath & fileName) as JPEG
					close
				end tell
			end tell
		end repeat
		tell application "Finder" to delete theFiles
	end if
end adding folder items to

Hi Stefan,
Thank you. You’re right, this works only for the last added file.
Is it possible for the script to start once there are four files in the folder and then process them all rather than the just the last added. I imagine it’s to do with a repeat but I don’t know how to script it.

Thanks,
JM