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