Re: Character to Umlaut Character?
Re: Character to Umlaut Character?
- Subject: Re: Character to Umlaut Character?
- From: Shane Stanley <email@hidden>
- Date: Fri, 27 Apr 2018 10:52:35 +1000
On 27 Apr 2018, at 4:35 am, Christopher Stone <email@hidden>
wrote:
>
> I'm looking for a method that would let me select any character, and the
> script would:
>
> - Copy it.
> - Determine if it could be transformed into an umlaut.
> - Transform it if possible.
> - Paste it back if necessary.
I presume you have items 1 and 4 under control, but item 2 is tricky because
you can add a combining diaeresis to any character. This code will add the
combining diaeresis, normalize, and then see if the normalization reduced the
number of unichars (16-bit units). Whether that's foolproof for all languages,
I don't know, but it's probably fine for your needs.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
addUmlautTo("u")
on addUmlautTo(theCharacter)
-- add combining diaeresis
set theCombo to theCharacter & character id 776
-- try to normalize
set newChar to current application's NSString's
stringWithString:theCombo
set theLength to newChar's |length|()
set newChar to newChar's precomposedStringWithCanonicalMapping()
-- check if normalization reduced length
if newChar's |length|() < theLength then
return newChar as text
else
return theCharacter
end if
end addUmlautTo
--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden