Два отличных решения здесь. Но так как каждая проблема обычно имеет много решений, я предлагаю другое:
property alphabet : "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ"
--------------------------------------------------------------------------------
rename from "HELLO World+Foo(\"Bar\")new.ext"
--------------------------------------------------------------------------------
### HANDLERS
#
# rename from:
# Receives a text string and processes it for invalid characters, which
# get replaced with the specified replacement string (default: "-"),
# returning the result
to rename from filename given disallowed:¬
invalidCharSet as text : "[()[\\/:\"*?<>|]+_] ", replaceWith:¬
replacementStr as text : "-"
local filename
local invalidCharSet, replacementStr
set my text item delimiters to {replacementStr} & ¬
the characters of the invalidCharSet
text items of the filename as text
makeLowercase(the result)
end rename
# makeLowercase():
# Receives a text string as input and returns the string formatted as
# lowercase text
to makeLowercase(str as text)
local str
set my text item delimiters to ""
if str = "" then return ""
set [firstLetter, otherLetters] to [¬
the first character, ¬
the rest of the characters] of str
tell the firstLetter to if ¬
it is "-" or ¬
it is not in the alphabet then ¬
return it & my makeLowercase(the otherLetters)
considering case
set x to (offset of the firstLetter in the alphabet) mod 27
end considering
return character x of the alphabet & my makeLowercase(the otherLetters)
end makeLowercase
Этот код можно использовать в действии Запуск AppleScript Automator , поместив rename from...
внутри обработчика on run {input, parameters}
, а остальную часть кода - вне его. Он может следовать за действием, которое снабжает его списком файлов в Finder , или он может получать свои входные данные непосредственно от ввода рабочего процесса, если он запускается как Служба .
property alphabet : "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ"
on run {input, parameters}
tell application "Finder" to repeat with f in input
set the name of f to (rename from f)
end repeat
end run
to rename from ...
.
.
end rename
to makeLowercase(str as text)
.
.
end makeLowercase