-
Notifications
You must be signed in to change notification settings - Fork 0
/
unicode2typPt1.applescript
88 lines (80 loc) · 2.63 KB
/
unicode2typPt1.applescript
1
-- Created by: Peter David Shannon-- Created on: 2016-04-11---- Copyright (c) 2016 Peter Shannon-- Feel free to modify the script for your own use, but leave the copyright notice intact.-- I use Keyboard Maestro to trigger this script if the clipboard changes.-- Perhaps there are some other automation programs which can do the same-- thing.on already_exists(pChar) -- Needed to add this check as the latest update for Keyboard Maestro now -- sometimes spots changes to the clipboard much more quicky tell application "Keyboard Maestro Engine" to set mRuleSetName to value of variable "unicodeRuleSet" tell application "Typinator" if exists rule set mRuleSetName then set mRuleSet to rule of rule set mRuleSetName repeat with mRule in mRuleSet set mExpansion to plain expansion of mRule as string if mExpansion = pChar then return true end if end repeat return false end if end tellend already_existson check_decimal(pInput) -- Is the input a single character and outside the ASCII range and in the unicode range? -- Is the input a single character, return -1? -- Or is the input an integer, return the integerp? set biggestAscii to 127 set biggestUnicode to 1114111 if length of pInput = 1 and id of pInput > biggestAscii and id of pInput ≤ biggestUnicode then -- this is a non-core-ascii unicode character return -1 else if length of pInput ≤ length of (biggestUnicode as string) then try set mNumber to pInput as number set mInteger to pInput as integer if mNumber = mInteger and mInteger > biggestAscii and mInteger ≤ biggestUnicode then return mInteger end if end try end if -- If we get here then it's not a unicode character or decimal number error "Not a unicode character or decimal number." number 1000end check_decimalon get_decimal_expansion(pDecimal) return "{Scripts/Unicode.applescript " & pDecimal & "}"end get_decimal_expansion-- main programtry set mInput to the clipboardon error -- if there is an error getting the clipboard contents, quit. return -1end trytry -- Quick check to see if the clipboard contents have a unicode character -- or decimal number. set mDecimal to check_decimal(mInput)on error errString number errNumber if errNumber = 1000 then -- The clipboard does not contain anything we should be trying to turn -- into a unicode expansion. return -1 else error errString number errNumber end ifend tryif mDecimal = -1 then set mChar to mInputelse set mChar to get_decimal_expansion(mDecimal)end if-- Check to see if we already have the expansionif not already_exists(mChar) then return mCharelse return -1end if