I have found a solution myself, and would like to share the result with you: I built a kind of clumsy function that finds and replaces the undesired chars if they appear in the string (unfortunately AppleScript returns bad results if the find-and-replace doesn't find an occurence.
Edit: As I have found the bracket chars to be uncritical, their transformation is excluded from the script pasted below. Therefore, the needles given at the bottom of the UnAccentString()
function must be adjusted, if brackets should be replaced, too.
The findAndReplace()
function is courtesy of MacScripter, thank you.
Be aware that the order of replacements within the UnAccentString()
function is crucial. When you place the 'Ü'-transformation above the 'ü', you will get bad results. Interestingly, OS X seems to consider an 'ü' as valid when looking for 'Ü's, but nor vice versa nor with other* umlauts. No idea why this is happening but it works with this order:
on UnAccentString(TheString)
if TheString contains "ü" then
set TheString to findAndReplace("ü", "Ue", TheString)
end if
if TheString contains "ä" then
set TheString to findAndReplace("ä", "ae", TheString)
end if
if TheString contains "ö" then
set TheString to findAndReplace("ö", "oe", TheString)
end if
if TheString contains "Ü" then
set TheString to findAndReplace("Ü", "Ue", TheString)
end if
if TheString contains "Ä" then
set TheString to findAndReplace("Ä", "Ae", TheString)
end if
if TheString contains "Ö" then
set TheString to findAndReplace("Ö", "Oe", TheString)
end if
if TheString contains "é" then
set TheString to findAndReplace("é", "e", TheString)
end if
if TheString contains "è" then
set TheString to findAndReplace("è", "e", TheString)
end if
if TheString contains "à" then
set TheString to findAndReplace("à", "a", TheString)
end if
if TheString contains "ó" then
set TheString to findAndReplace("ó", "o", TheString)
end if
if TheString contains "á" then
set TheString to findAndReplace("á", "a", TheString)
end if
if TheString contains "ú" then
set TheString to findAndReplace("ú", "u", TheString)
end if
if TheString contains "í" then
set TheString to findAndReplace("í", "i", TheString)
end if
if TheString contains "Á" then
set TheString to findAndReplace("Á", "A", TheString)
end if
if TheString contains "É" then
set TheString to findAndReplace("É", "E", TheString)
end if
if TheString contains "Í" then
set TheString to findAndReplace("Í", "I", TheString)
end if
if TheString contains "Ó" then
set TheString to findAndReplace("Ó", "O", TheString)
end if
if TheString contains "Ú" then
set TheString to findAndReplace("Ú", "U", TheString)
end if
if TheString contains "ñ" then
set TheString to findAndReplace("ñ", "n", TheString)
end if
if TheString contains "Ñ" then
set TheString to findAndReplace("Ñ", "N", TheString)
end if
if TheString contains "ê" then
set TheString to findAndReplace("ê", "e", TheString)
end if
if TheString contains "Ê" then
set TheString to findAndReplace("Ê", "E", TheString)
end if
if TheString contains "ë" then
set TheString to findAndReplace("ë", "e", TheString)
end if
if TheString contains "Ë" then
set TheString to findAndReplace("Ë", "E", TheString)
end if
if TheString contains "È" then
set TheString to findAndReplace("È", "E", TheString)
end if
if TheString contains ":" then
set TheString to findAndReplace(":", "", TheString)
end if
if TheString contains "," then
set TheString to findAndReplace(",", "", TheString)
end if
if TheString contains " " then
set TheString to findAndReplace(" ", "-", TheString)
end if
if TheString contains "%" then
set TheString to findAndReplace("%", "", TheString)
end if
if TheString contains "'" then
set TheString to findAndReplace("'", "", TheString)
end if
return TheString & ".pdf" as text
end UnAccentString
on findAndReplace(tofind, toreplace, TheString)
set ditd to text item delimiters
set res to missing value
set text item delimiters to tofind
repeat with tis in text items of TheString
if res is missing value then
set res to tis
else
set res to res & toreplace & tis
end if
end repeat
set text item delimiters to ditd
return res
end findAndReplace
Therefore, calling the function with the following string:
return UnAccentString("Übersetzungen im alltäglichen Leben eines Riñóns und eines Négligée à Noël") as text
will return
Uebersetzungen-im-alltaeglichen-Leben-eines-Rinons-und-eines-Negligee-a-Noel
This is a list of all the characters that the function looks for and their respective counterparts they're getting replaced with:
- Ü --> Ue
- Ä --> Ae
- Ö --> Oe
- ü --> Ue
- ä --> ae
- ö --> oe
- é --> e
- è --> e
- à --> a
- ó --> o
- á --> a
- ú --> u
- í --> i
- Á --> A
- É --> E
- Í --> I
- Ó --> O
- Ú --> U
- ñ --> n
- Ñ --> N
- ê --> e
- Ê --> E
- ë --> e
- Ë --> E
- È --> E
- : --> (null)
- , --> (null)
- (space) --> -
- % --> (null)
- ' --> (null)
I hope that helps anyone.
Cheers, nic.