1

I am trying to build the following services:

  1. Change type of image, result in the same folder (image.jpg => image.jpg + image.png)
  2. Change size of image, result in the same folder (image.jpg => image.jpg + image-800x600.jpg)

I am stuck on part where the original image is duplicated in the same folder, under a different name (the copy finder item workflow requires a hard coded destination or other option I am not familiar with).

Maybe I could use a shell script to perform the duplicating part. I know how to get the file paths passed to the run shell script workflow, but I can't figure out how to send valid paths out to the next task (change type or resize).

MAC OS version is Mountain lion 10.8.2.

Jean
  • 7,623
  • 6
  • 43
  • 58
  • 1
    Can you explain your workflow step by step? – adayzdone Nov 07 '12 at 12:58
  • 2
    Thanks for your reply. I haven't a workflow yet. The only thing I can do is accept images from the finder, add a copy finder items action (which doesn't do what I would like) and add the conversion (resize or change type) action. The result is the right operation done in the wrong folder. – Jean Nov 07 '12 at 15:01

1 Answers1

4

You can duplicate the files before you scale them:

on run {input}
    set newFiles to {}
    repeat with aFile in input
        tell application "Finder" to set myFile to duplicate aFile
        set end of newFiles to myFile as alias
    end repeat
    delay 1
    return newFiles
end run

enter image description here

You can add another AppleScript at the end to deal with the files names:

on run {input}
    repeat with myFile in input
        tell application "System Events" to set oldName to myFile's name
        set newName to do shell script "echo " & quoted form of oldName & " | sed -E 's/ ?copy ?[0-9?]*//'"
        tell application "System Events" to set myFile's name to newName
    end repeat
end run
adayzdone
  • 11,120
  • 2
  • 20
  • 37
  • 2
    Thanks, a thousand times. It works perfectly. Now, to achieve my goal, I have added a rename file action at the end of the workflow to replace " copy" either with nothing in case of a type change or with "-800x600" in case of a resize operation. But it isn't perfect (for instance, any file already containing " copy" prior to the transformation will generate a " copy 1" duplicate. the " 1" will remain after renaming the file. Any suggestions ? – Jean Nov 07 '12 at 19:46