With the generous help of StefanK I was able to get my original script to work flawlessly. While his recommended shell script did the trick in getting it to work I ran into trouble when I tried to modify it for another application. I have a difficult enough time grasping basic Applescript so deciphering and tweaking a shell script was way beyond my scope and I went back to trying my hand at reworking it with the basic Applescript code I know.
Amazingly, I got it to work… kind of.
The script creates a folder at the root of the HD with a unique name generated by a filemaker database record field and a text string
It then monitors a watch folder for image files downloaded to it randomly from a tethered camera and processes those files with a Photoshop Action, prints and saves the file with it’s original name back to the watch folder.
The script then renames the processed file with the database prefix, a text string, and then what I assumed would be a unique date and time stamp suffix (I added a numbered sequence loop to the file name just to ensure the name would truly be unique) and then moves the renamed file from the watch folder to the folder generated at the beginning of the script.
Everything seems to work fine with the first file the script sees and processes but for some reason, which I can’t for the life of me figure out, the script seems to name the subsequent files with the exact same name as the first file so I get an error message that the file already exists in the new folder.
Could someone please tell me where I’ve gone wrong in my logic (now that’s a loaded question)?
Thanks again to all those members who help us newbies out so patiently.
Regards,
kevlar
--This gets receipt number from Filemaker Sales Receipt database customer record
tell application "FileMaker Pro"
set myCell to cell "Receipt_Number" of current record
end tell
--This creates folder at root of HD with receipt number as folder name prefix and current date as suffix
tell application "Finder"
set D to current date
set myShortDate to short date string of D as string
make new folder at "Macintosh HD" with properties {name:myCell & "_" & "ForesidePhotography.com" & "_" & myShortDate}
set newFolderPath to result as Unicode text
end tell
--This loop checks to see if watch folder "Camera_Images" has had any images downloaded into it
repeat
tell application "Finder" to set FileList to files of folder "Macintosh HD:Camera_Images:"
set CountOfFileList to (count of FileList)
if CountOfFileList > 0 then
exit repeat
end if
end repeat
--Files detected in watch folder are then processed with Photoshop action, printed and saved with the original file name back to watch folder
activate application "Adobe Photoshop CS4"
set item_no to 0
repeat with FileToOpen in FileList
tell application "Adobe Photoshop CS4"
open (FileToOpen as alias)
do action "Photo Process" from "Photo Actions"
end tell
--GUI and Sysytem Events are used here to print because particular printer used requires a unique paper size
tell application "System Events"
tell process "Photoshop"
keystroke "p" using {command down}
key code 36
delay 2
key code 36
delay 40
keystroke "s" using {command down}
delay 2
key code 36
end tell
end tell
tell application "Adobe Photoshop CS4" to close document 1
--File is then renamed with Filemaker data prefix, a text string, and then a date and time stamp suffix
tell application "Finder"
set DTime to time string of D as string
set myDateTime to (myShortDate & "_" & DTime)
set the name of file (FileToOpen as alias) to (myCell & "_" & "Image_Processed" & "_" & myDateTime & "_" & (item_no + 1) & ".jpg")
set theRenamedFile to result
set CameraImagePath to "Macintosh HD:Camera_Images:"
set theRenamedFilePath to CameraImagePath & theRenamedFile as Unicode text
end tell
--Renamed File is then moved to the unique customer folder created in beginning of script
tell application "Finder"
move file theRenamedFilePath to folder newFolderPath
end tell
--process repeats until watch folder is empty
end repeat
return (0.1 * minutes)
Model: MacBook Pro 2.66 OSX10.6.4
AppleScript: 2.1.2
Browser: Safari 533.16
Operating System: Mac OS X (10.6)