Author
Topic: Help with renaming - please.... (Read 3941 times)

Platform - PowerMac 7300/200 with 48mb RAM and 1.5gb HD, OS9.2.2. (I use this as my AS server) It's already running several scripts.

Here is the script I am having issues with:

property processed_folder : "PHOTO:PROCESSED:" as alias

on adding folder items to this_folder after receiving added_items tell application "Finder" end tell tell application "Finder" move added_items to processed_folder end tell repeat with file_ in added_items tell application "Finder" if file type of (info for file_) is "jpg" then try set the suffix to "_cmyk.jpg" set name of file_ to text 1 thru -5 of (get name of file_) & suffix on error e display dialog e end try end if end tell -- tell application "Adobe® Photoshop® 5.5" -- activate -- open theFile -- tell front document -- do script "CMYK" -- end tell -- end tell end repeat

end adding folder items to

I have the Photoshop stuff commented out until I get the renaming nailed down.

The script was modified from one that I had tested and had working on my G5 desktop. Essentially, it's a FAS that moves the added files to a new folder (so I don't get into a loop), renames the filename of a JPG to include the orignal filename + _cmyk at the end and then the three letter extension. It then calls Photoshop to run an action which saves the jpg as a tif in another location and then closes the file. My working OSX script does not work over the network either. "Can't get name blah, blah, blah as alias" is the error I keep getting.

The OS9 script moves my files but stalls at the rename. Can anyone tell me what I am doing wrong here? I've spent all day on this and no joy.

Eric, as Emma has pointed out "file type" is always "JPEG" thats 4 characters even in the case of "PDF " the space after "F" is important. What you can use for jpg is "name extension" in Finder the thing to keep in mind here is when using "name extension" is that files can also be jpeg you can make lists to catch this and in addition to that include "missing value" as part of list.

Heres a quick and easy finder snippet to just check for what you want.

set inputFile to choose file with prompt "Where is the file?"001setinputFiletochoose filewith prompt "Where is the file?"002tellapplication "Finder"003 -- each property this is not all of them!!!004getmodification dateoffileinputFile005getcreation dateoffileinputFile006getfile typeoffileinputFile007getnameoffileinputFile008getcreator typeoffileinputFile009getname extensionoffileinputFile010getcommentoffileinputFile011getkindoffileinputFile012 -- or the lot013getpropertiesoffileinputFile014endtell

If you are making changes to an image file and renaming to new location then why not try open and save to new file path. This way the orginal is retained until you see fit to remove. I've had a guess at what your action contains you can always swap it back. Also see how to comment out chunks of code it can be a useful time saver. Here is a basic script that should only process JPEG's

This works with a quick test on X.3.9 sorry but I didn't even know of AppleScript back in the days of using Classic

Thanks for all the suggestions. I'm going to try this out. I realized after I posted this that my query should have been more of a Finder query and not so much Photoshop because the block for that part of the script was working. No issues with that.

I do have a question on larsen67's code though. I see it's calling Photoshop CS2. I understand that since Photoshop 7 (with a plug-in), Photoshop is more scriptable, but will this work on Photoshop 5.5? That's the version running on the Mac I'm using as an AS server. I'd like to keep it on that Mac if I could. The only reason I know that my script was not working over the network on my G5 is because in frustration I elected to try it. It's working just fine with any files/folders on my G5 only. But even if I have to ultimately use my G5 for this, I only have Photoshop 7. So would that work with the scripting plug-in?

Eric, like I said i only started scripting some 18 months or so ago. I've never scripted with Classic apps the only thing I would know to do is open the said applications dictionary to see if the terms existed back then. What is in the script are very basic commands. In fact this could all be done with actions from CS onwards. Using conditional mode change. I would imagine any missing terms would be highlighted when it can't complie in SE?

I'm still checking this out, but in regards to the AS dictionarys, both the one for Photoshop 5.5 and 7 (without the scripting plug-in) have the sum total of 2 commands (that I can see). Open and do script, with some other stuff in there for droplets. I'll keep cracking at it. Thanks.

Ok, been playing around with this all day again. Found out a bit about AppleScript Text Item Delimiters. So. Now my script will copy jpgs to the proper process folder with the proper suffix, ie, incoming files named filename1.jpg, filename2.jpg and so on are now appropriately renamed filename1_cmyk.jpg and filename2_cmyk.jpg and so on. Anything that is not a JPG gets routed to an error folder. Since we have much less of these (PDFs, BMPs, GIFs, etc) I can process those seperately.

What I can't seem to get is Photoshop 5.5 to open the files and do the script. Here's what I have:

on adding folder items to this_folder after receiving added_items repeat with i from 1 to the number of items in added_items set the_file to item i of added_items tell application "Finder" if file type of (info for the_file) is in the extension_list then try my file_rename(the_file) move file the_file to folder destfolder with replacing my do_pscript(the_file) end try else move file the_file to folder error_folder with replacing end if end tell end repeatend adding folder items to

on file_rename(the_file) try tell application "Finder" to set tName to name of the_file set {oAStID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ".jpg"} set tString to text items of tName set AppleScript's text item delimiters to "_" set tString to tString as string set AppleScript's text item delimiters to oAStID tell application "Finder" to set name of the_file to tString & fString01 & ".jpg" end tryend file_rename

AND it's working. So, here's what's happening. File get's dumped into an IN folder based on the colorspace the operator needs (I also have a Grayscale version of this, but I needed to get this working first so I could dupe the script and switch the PS Action it calls), it get's renamed to: filename_cmyk.jpg or filename_bw.jpg, depending on the case, processed in PS, and then moved to a Processed folder. The PS action takes care of a "Save As..." TIF format into another network folder where the operator then picks up filename_cmyk.tif or filename_bw.tif.

I would ultimately have preferred not moving the files and just renaming inside the folder, but since this is a FAS a filerename would just lock me into a loop.

Eric, Im glad you've got it working but like I said when using "name extension" rather than "file type" in script I always put both options in list just to be sure. Especially if image are being supplied from various sources. Just something that you do need to be aware of.