Umlaute und Sonderzeichen in Datei- und Ordnernamen ersetzen
2/08/2011-- hubionmac.com 02.08.2011
-- ersetzt in einem Verzeichnis und allen Unterordnern Sonderzeichen (Umlaute) in Datei und Ordnernamen
-- es können so nur einzelne Sonderzeichen gegen Zeichenketten ersetzt werden ä ->ae
set replacements_list to {{"Ä", "Ae"}, {"ä", "ae"}, {"Ö", "Oe"}, {"ö", "oe"}, {"Ü", "ue"}, {"ü", "ue"}, {"/", "_"}}
set thefolder to choose folder
set thefiles_x to do shell script "find " & quoted form of (POSIX path of thefolder) & " -not -name \".*\""
-- Baut sich eine Liste aus Aliasen, damit die Pfadangaben auch noch funktionieren,
--wenn mal ein übergeordnetes Verzeichnis bereits vom Skript umbenannt wurde
set thefiles to {}
repeat with thefile in every paragraph of thefiles_x
set thefiles to thefiles & ((POSIX file thefile) as alias)
end repeat
repeat with thefile in thefiles
tell application "Finder"
set thefilename to name of thefile
set old_filename to thefilename
end tell
repeat with replacement in replacements_list
set badchar to ASCII number of ((item 1 of replacement) as text)
set thefilename_ascii to asciilist(thefilename)
if badchar is in thefilename_ascii then
set thefilename to my replace_string(thefilename, ASCII character badchar, (item 2 of replacement) as text)
end if
end repeat
if old_filename ≠ thefilename then
tell application "Finder"
set name of thefile to thefilename
end tell
end if
end repeat
on replace_string(itemname, searchstring, replacestring)
set old_delimiter to AppleScript's text item delimiters
set AppleScript's text item delimiters to searchstring
set the item_list to every text item of itemname
set AppleScript's text item delimiters to replacestring
set this_text to the item_list as string
set AppleScript's text item delimiters to old_delimiter
return this_text
end replace_string
on asciilist(thestring)
set myoutput to {}
repeat with a in every character of thestring
set myoutput to myoutput & (ASCII number of a)
end repeat
return myoutput
end asciilist