Automator: Move files into new subfolder based on file's name

Solution 1:

I had a similar question and with the help of wch1zpink came up with this solution. In automator:

  1. create a new workflow
  2. add get selected finder items
  3. add run applescript
  4. replace the script with this:

    tell application "Finder"
        set selectedFiles to selection as alias list
        set containingFolder to container of item 1 of selectedFiles as alias
        repeat with i from 1 to count of selectedFiles
            set thisItem to item i of selectedFiles
            set fileName to (text items 1 thru -5) of (name of thisItem as text) as string
            move thisItem to (make new folder at containingFolder ¬
                with properties {name:fileName})
        end repeat
    end tell