Umlaute und Sonderzeichen in Datei- und Ordnernamen ersetzen

2/08/2011
Das war der Auslöser und es hier meine Lösung dazu:

-- 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_filenamethefilename 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

1 Comment

AppleScript: Search&Replace im Adressbuch

14/03/2010
Vielleicht auch praktisch, das Ding durchsucht Adressen im Adressbuch nach Zeichen (im Code werden Zeilenumbrüche ersetzt) in den Adress-Feldern und löscht diese. :-?
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

--script to remove certain characters/strings from an address

set toBeRemoved to {"

"}

tell application "Address Book"

set my_selections to selection

repeat with my_selection in my_selections

repeat with i from 1 to count of every address of my_selection

repeat with current_replace_string in toBeRemoved

set current_replace_string to current_replace_string as text

set street of address i of my_selection to my replace_chars((street of address i of my_selection), current_replace_string, "")

set city of address i of my_selection to my replace_chars((city of address i of my_selection), current_replace_string, "")

set zip of address i of my_selection to my replace_chars((zip of address i of my_selection), current_replace_string, "")

set country of address i of my_selection to my replace_chars((country of address i of my_selection), current_replace_string, "")

set state of address i of my_selection to my replace_chars((state of address i of my_selection), current_replace_string, "")

end repeat

end repeat

end repeat

save

end tell

to replace_chars(this_text, search_string, replacement_string)

if this_text contains the search_string then

set AppleScript's text item delimiters to the search_string

set the item_list to every text item of this_text

set AppleScript's text item delimiters to the replacement_string

set this_text to the item_list as string

set AppleScript's text item delimiters to ""

end if

return this_text

end replace_chars

No Comments