OS X Automator Workflow: Automatically Rename Files Based On Download Source

My first solution for this problem involved Hazel. Since my colleagues don’t use this precious little tool, I wanted to achieve the same with Automator and Folder Actions. For this to work, I had to include the renaming part into the Applescript. Screenshot: OS X Automator Workflow for renaming files based on their download source If you’re interested in stuff like this, it should be no big problem to change the script according to your needs. (My version renames images (jpg) dropped on my desktop, that have name beginning with »large«. It changes the name to a string containing the Shutterstock-ID.)

The Applescript part:

on run {input, parameters}
    set newnames to {}
    repeat with singleFile in input
        set realFile to contents of singleFile
        set the_path to POSIX path of singleFile
        set the_itemfroms to "kMDItemWhereFroms" as Unicode text
        set v to (do shell script "mdls -name " & the_itemfroms & space & the_path)

        set AppleScript's text item delimiters to {"/"}
        set the_id to sixth text item of v
        set the_newname to "stock-photo-shutterstock-" & the_id & ".jpg"
        set newnames to newnames & the_newname
        tell application "Finder" to set name of file realFile to the_newname
    end repeat
    return newnames
end run
fab1An @fab1An