Skip to main content
2 of 5
added 288 characters in body
Lri
  • 106.4k
  • 19
  • 230
  • 283

Paste as a Run Shell Script action and select Pass input: as arguments:

for f in "$@"; do new="$(echo "$f" | sed -E 's|/$||;s| +$||;s|^ +||;s|/ +([^/]+$)|/\1|;s| +\.([^.][a-zA-Z0-9\.]*)$|.\1|g')"; mv "$f" "$new"; echo "$new"; done

Should work with:

  • somefile .tar.gz
  • EOL + ..plist
  • Terra Nova.S01E05.avi
  • ../ somefile.txt
  • ./somedir /

Doesn't work as expected with:

  • Terra Nova .S01E05.avi
Lri
  • 106.4k
  • 19
  • 230
  • 283