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

0 Members and 1 Guest are viewing this topic.

Offline Erik Youngren

  • Jr. Member
  • **
  • Posts: 52
  • Karma: 1
  • Gender: Male
  • Robotech and Rolemaster freak.
    • Wandering Monk Rolemaster Forums
Help with renaming - please....
« on: May 17, 2007, 07:11:45 PM »
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.

Thanks in advance for any help.

Erik Youngren
Wandering Monk Rolemaster Forums
17" Powerbook G4 1.67Ghz • 2GB RAM •OSX 10.4.11 • QXP 8.5 • ID CS4 • Suitcase Fusion 2

Offline Emma

  • Full Member
  • ***
  • Posts: 205
  • Karma: 9
Re: Help with renaming - please....
« Reply #1 on: May 18, 2007, 03:16:42 AM »
I may be completely muddled here, but when I point this fragment of script at a JPEG

set file_ to choose file
display dialog "file type is " & file type of (info for file_)

it returns "JPEG", not "JPG". Now, since your script was working before, that probably isn't it, but it is odd... Are there 2 different file types for JPEGs?
------------
Quark 6.5
OS X 10.4.8
G4

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Help with renaming - please....
« Reply #2 on: May 18, 2007, 04:53:37 AM »
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?"
001   set inputFile to choose file with prompt "Where is the file?"
002   tell application "Finder"
003        -- each property this is not all of them!!!
004        get modification date of file inputFile
005        get creation date of file inputFile
006        get file type of file inputFile
007        get name of file inputFile
008        get creator type of file inputFile
009        get name extension of file inputFile
010        get comment of file inputFile
011        get kind of file inputFile
012        -- or the lot
013        get properties of file inputFile
014   end tell

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

001   on adding folder items to this_folder after receiving these_items
002        tell application "Finder"
003             if not (exists folder "Processed Images" of desktop) then
004                  set destination_folder to make new folder at desktop with properties {name:"Processed Images"}
005             else
006                  set destination_folder to folder "Processed Images" of desktop as string
007             end if
008        end tell
009        repeat with an_item in these_items
010             tell application "Finder"
011                  set theFile to an_item as alias
012                  if file type of (info for theFile) is "JPEG" then
013                       with timeout of 15 seconds
014                            tell application "Adobe Photoshop CS2"
015                                 activate
016                                 set display dialogs to never
017                                 open theFile
018                                 set docRef to the current document
019                                 set docName to name of docRef
020                                 set docBaseName to my getBaseName(docName)
021                                 tell docRef
022                                      if (mode is not CMYK) then
023                                           change mode to CMYK
024                                      end if
025                                      -- Below is the easier way to commentout a chunk of code…
026                                      (* if (bits per channel is sixteen) then
027                                           set bits per channel to eight
028                                      end if *)
029                                      --
030                                      set newFileName to (destination_folder as string) & docBaseName & "_CMYK.jpg"
031                                      save docRef in file newFileName as JPEG with options ¬
032                                           {class:JPEG save options, embed color profile:true, format options:optimized, matte:background color matte, quality:12}
033                                 end tell
034                                 close current document without saving
035                            end tell
036                       end timeout
037                  end if
038             end tell
039        end repeat
040   end adding folder items to
041   --
042   on getBaseName(fName)
043        set baseName to fName
044        repeat with idx from 1 to (length of fName)
045             if (item idx of fName = ".") then
046                  set baseName to (items 1 thru (idx - 1) of fName) as string
047                  exit repeat
048             end if
049        end repeat
050        return baseName
051   end getBaseName


Offline Erik Youngren

  • Jr. Member
  • **
  • Posts: 52
  • Karma: 1
  • Gender: Male
  • Robotech and Rolemaster freak.
    • Wandering Monk Rolemaster Forums
Re: Help with renaming - please....
« Reply #3 on: May 18, 2007, 10:26:19 AM »
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?

Erik Youngren
Wandering Monk Rolemaster Forums
17" Powerbook G4 1.67Ghz • 2GB RAM •OSX 10.4.11 • QXP 8.5 • ID CS4 • Suitcase Fusion 2

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Help with renaming - please....
« Reply #4 on: May 18, 2007, 10:48:58 AM »
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?

Offline Erik Youngren

  • Jr. Member
  • **
  • Posts: 52
  • Karma: 1
  • Gender: Male
  • Robotech and Rolemaster freak.
    • Wandering Monk Rolemaster Forums
Re: Help with renaming - please....
« Reply #5 on: May 18, 2007, 11:11:30 AM »
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.

Erik Youngren
Wandering Monk Rolemaster Forums
17" Powerbook G4 1.67Ghz • 2GB RAM •OSX 10.4.11 • QXP 8.5 • ID CS4 • Suitcase Fusion 2

Offline Erik Youngren

  • Jr. Member
  • **
  • Posts: 52
  • Karma: 1
  • Gender: Male
  • Robotech and Rolemaster freak.
    • Wandering Monk Rolemaster Forums
Re: Help with renaming - please....
« Reply #6 on: May 18, 2007, 07:07:24 PM »
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:

property extension_list : {"jpeg"}
property destfolder : "PHOTO:PROCESSED:"
property error_folder : "PHOTO:ERROR:"
property fString01 : "cmyk"

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 repeat
end 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 try
end file_rename

on do_pscript(the_file)
   tell application "Adobe® Photoshop® 5.5"
      activate
      open the_file
      tell front document
         do script "CMYK"
      end tell
   end tell
end do_pscript

Anyone have an ideas? Either PS activates and then just sits there or I get a file error (error -43 or -1700). Thanks for any info you guys can give me.

PS, Emma and larsen67 you were of course right about the "file type (info for this_item) is "JPEG""  Once I had that in things were processing only JPEGs. Thanks, all again.

Erik Youngren
Wandering Monk Rolemaster Forums
17" Powerbook G4 1.67Ghz • 2GB RAM •OSX 10.4.11 • QXP 8.5 • ID CS4 • Suitcase Fusion 2

Offline Erik Youngren

  • Jr. Member
  • **
  • Posts: 52
  • Karma: 1
  • Gender: Male
  • Robotech and Rolemaster freak.
    • Wandering Monk Rolemaster Forums
Re: Help with renaming - please....
« Reply #7 on: May 18, 2007, 09:00:59 PM »
OK, final update on this if anyone wants to know. I switched these two lines:

  move file the_file to folder destfolder with replacing
  my do_pscript(the_file)

to this:

  my do_pscript(the_file)
  move file the_file to folder destfolder with replacing

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.

Anyway, hope that might help anyone else out there.
« Last Edit: May 18, 2007, 09:03:40 PM by Erik Youngren »

Erik Youngren
Wandering Monk Rolemaster Forums
17" Powerbook G4 1.67Ghz • 2GB RAM •OSX 10.4.11 • QXP 8.5 • ID CS4 • Suitcase Fusion 2

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Help with renaming - please....
« Reply #8 on: May 21, 2007, 03:28:48 AM »
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.

property extension_list : {"jpeg", "jpg"}

Offline Erik Youngren

  • Jr. Member
  • **
  • Posts: 52
  • Karma: 1
  • Gender: Male
  • Robotech and Rolemaster freak.
    • Wandering Monk Rolemaster Forums
Re: Help with renaming - please....
« Reply #9 on: May 21, 2007, 10:22:27 AM »
Good to know. Thanks. I plan on modifications when I get a chance so that it'll run off on BMP and GIF files (some of our other file types we get from editorial). Thanks again.

Erik Youngren
Wandering Monk Rolemaster Forums
17" Powerbook G4 1.67Ghz • 2GB RAM •OSX 10.4.11 • QXP 8.5 • ID CS4 • Suitcase Fusion 2