Search code examples
copyosx-mountain-lionautomatorduplicationin-place

Automator: duplicate OR copy in place


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.


Solution

  • 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