Search code examples
screenshotautomator

Use automator to batch rename images


I have a whole folder of screenshots with file names like this:

http_www.mozilla.org.png
http_www.google.com.png

I want to remove every element before the www. and every element after the .org or .com

What should I do in automator on mac to achieve something like this?

Thanks


Solution

  • If you are trying to rename them, try this AppleScript:

       tell application "Finder" to set myFiles to files of (choose folder)
    repeat with aFile in myFiles
        tell application "System Events" to set fileName to aFile's name
        set newName to do shell script "echo " & quoted form of fileName & " | sed 's/.*www\\.\\([A-Za-z0-9]*\\).*\\(\\.png$\\)/\\1\\2/'"
        tell application "System Events" to set aFile's name to newName
    end repeat