Close to working but get Class error

First off, thanks to all who have helped me get this far. As a relative newbie to scripting it is greatly appreciated. Trying to learn Applescript strictly from reading the books I’ve purchased (Applescript for Dummies, Beginning Applescript and Applescript - The Missing Manual) has been helpful but often seems like trying to learn to speak French by only referring to textbooks… frustrating. This forum is a Godsend.

That being said, I have cobbled together a script that, while not elegant, actually worked (there is no greater thrill than having your script accomplish what you intended) until I tweaked it with a couple lines of code near the end.

The script basically runs in the background and processes a series of image files (IMG_0001.jpg, IMG_0002.jpg, etc.) that are downloaded at random times and frequency from a tethered camera to a folder “Macintosh HD:Camera_Images” that the script monitors.

The script then opens the file in Photoshop, applies a processing action, then prints the file to a specified printer.
In the original script that worked it then closed the file and just moved it to another folder “Macintosh HD:Processed_Images”.

I decided to get creative and add some code that would rename the file to “This File Processed” and “the current Date and Time”, then to move it.

I got the new script to change the name correctly but I keep getting a variety of “Can’t set <> yadda yadda” error messages when it attempts the file move no matter how many variations of code examples I’ve found and tried to apply.

I’ve read countless posts on renaming files and have tried every version of syntax posted but still can’t seem to grasp the whole “alias/unicode” mechanics to solve what seems to be a relatively simple task.

Any help would, again, be greatly appreciated. (please forgive the awkward coding in my script)

I’ve commented what I think to be the problem code.

Thanks,

Kevlar


on idle
	with timeout of 2000 seconds
		set theDestinationFolder to "Macintosh HD:Processed_Images"
		tell application "Finder"
			set FileList to items of folder "Macintosh HD:Camera_Images"
			repeat while FileList = 0
			end repeat
			repeat with i from 1 to the number of items in the FileList
				set FileToOpen to item i of FileList
				tell application "Adobe Photoshop CS4" to open (FileToOpen as alias)
				tell application "Adobe Photoshop CS4"
					do action "Photobooth Process" from "Photo Booth Actions"
				end tell
				
				tell application "System Events"
					activate
					tell process "Photoshop"
						set frontmost to true
						keystroke "p" using {command down}
						key code 36
						delay 2
						key code 36
						delay 40
						keystroke "w" using {command down}
						delay 2
						keystroke "d"
						key code 36
					end tell
				end tell
				tell application "Finder"
					set D to current date
					set myShortDate to short date string of D as string
					set DTime to time string of D as string
					set myDateTime to (myShortDate & "_" & DTime)
					set ASTID to AppleScript's text item delimiters
					set newName to ("This File Processed" & "_" & myDateTime & ".jpg")
					set name of FileToOpen to newName
--Script works and does change the file name in the Finder window
					set newFileString to FileToOpen as Unicode text
					set FileToMove to alias ("Macintosh HD:Camera_Images" & newFileString)
					tell application "Finder"
--I believe this is where I get the error and the newly named file is not moved
						move FileToMove to "Macintosh HD:Processed_Images"
					end tell
				end tell
				delay 10
			end repeat
		end tell
		return (0.5 * minutes)
	end timeout
end idle

Model: MacBook Pro 2.66 OSX10.6.4
AppleScript: 2.1.2
Browser: Safari 533.16
Operating System: Mac OS X (10.6)

Hi,

you try to move the file to a literal string (path), not to a folder


move FileToMove to folder "Macintosh HD:Processed_Images:"

I recommend to use the shell for the time stamp and the file move,
because you can move and rename the file at the same time.


on idle
	with timeout of 2000 seconds
		tell application "Finder" to set FileList to files of folder "Macintosh HD:Camera_Images:"
		activate application "Adobe Photoshop CS3"
		repeat with FileToOpen in FileList
			tell application "Adobe Photoshop CS3"
				open (FileToOpen as alias)
				do action "Photobooth Process" from "Photo Booth Actions"
			end tell
			
			tell application "System Events"
				tell process "Photoshop"
					keystroke "p" using {command down}
					key code 36
					delay 2
					key code 36
					delay 40
				end tell
			end tell
			tell application "Adobe Photoshop CS3" to close document 1 without saving
			set newPath to "/Processed_Images/This File Processed_" & (do shell script "/bin/date +%d.%m.%Y_%H:%M:%S.jpg")
			do shell script "/bin/mv " & quoted form of POSIX path of (FileToOpen as text) & space & quoted form of newPath
			delay 10
		end repeat
		return (0.5 * minutes)
	end timeout
end idle


I’m quite sure you can print the files without GUI scripting, the dictionary of Photoshop is quite rich

Thank you so much Stefan. Some day I will begin to understand how all these variables work but for now I’ll have to learn from the masters!

There was an original method to my madness in using the GUI scripting to print from PhotoShop. The particular printer I am using uses a unique paper size that I couldn’t seem to coerce from Photoshop’s commands in the page setup menu, so I ended up having to set that printer and it’s particular paper size as a user preset so it always shows up in the print dialogue box as the default. The GUI accepts the default “okay” buttons in the 2 sequential dialogue boxes of the print sequence (hence the delay commands)

I like the elegance of your script though it will take some time for me to grasp shell scripts. It worked perfectly. I do have one question, however. My original script gave me a new file name with the Time Stamp derived from the system clock preferences where I could customize the format as needed. I configured it so it would give me this as a file name:

File Processed_08.03.10_09.32.40AM.jpg

So there was an AM/PM descripter (We still use the arcane 12 hour clock in America!). Is there a way to coerce that and add it to the shell script you devised?

Thanks again for all your help. I’m making a donation to MacScripter on your behalf to show my appreciation.

Best wishes.

-kevlar

No problem


.
set newPath to "/Processed_Images/This File Processed_" & (do shell script "/bin/date +%m.%d.%y_%I.%M.%S%p.jpg")
.