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)