Skip to content

Instantly share code, notes, and snippets.

@neophit
Last active July 7, 2019 12:01
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neophit/8090330 to your computer and use it in GitHub Desktop.
Save neophit/8090330 to your computer and use it in GitHub Desktop.
Add useful keyboard text shortcuts for exponents and fractions to your System Preferences. With iCloud enabled, these shortcuts will sync with your iOS devices. Tested on OS X 10.9.1 and iOS 7.0.4. Requires GUI Scripting Access: http://support.apple.com/kb/HT5914 (Based partially on this script: https://gist.github.com/Zettt/7724258)
set clickDelay to 0.3
set textReplaceList to {}
set exponentsListName to "Exponents (replaces ^0-^9 with ⁰-⁹)"
set fractionsListName to "Fractions (replaces 1/2-7/8 with ½-⅞)"
set exponentsList to {{"^0", "⁰"}, {"^1", "¹"}, {"^2", "²"}, {"^3", "³"}, {"^4", "⁴"}, {"^5", "⁵"}, {"^6", "⁶"}, {"^7", "⁷"}, {"^8", "⁸"}, {"^9", "⁹"}}
set fractionsList to {{"1/2", "½"}, {"1/3", "⅓"}, {"1/4", "¼"}, {"1/5", "⅕"}, {"1/6", "⅙"}, {"1/7", "⅐"}, {"1/8", "⅛"}, {"1/9", "⅑"}, {"1/10", "⅒"}, {"2/3", "⅔"}, {"2/5", "⅖"}, {"3/4", "¾"}, {"3/5", "⅗"}, {"3/8", "⅜"}, {"4/5", "⅘"}, {"5/6", "⅚"}, {"5/8", "⅝"}, {"7/8", "⅞"}}
set chosenLists to (choose from list {exponentsListName, fractionsListName} with title "Useful Keyboard Text Shortcuts" with prompt "Choose one or more sets of keyboard text shortcuts to add to your System Preferences.
This may take a minute to complete." OK button name "Add text shortcuts" cancel button name "Cancel" default items {exponentsListName, fractionsListName} with multiple selections allowed)
if the chosenLists is false then return
if chosenLists contains exponentsListName then set textReplaceList to textReplaceList & exponentsList
if chosenLists contains fractionsListName then set textReplaceList to textReplaceList & fractionsList
tell application "System Preferences"
activate
delay 5
activate
set keyboardPane to "com.apple.preference.keyboard"
set the current pane to pane id keyboardPane
reveal anchor "text" of pane id keyboardPane
delay 2
tell application "System Events"
repeat with i from 1 to ((count of textReplaceList))
click button 1 of group 1 of tab group 1 of window "Keyboard" of application process "System Preferences"
delay clickDelay
keystroke (item 1 of (item i of textReplaceList)) & "\t"
set the clipboard to (item 2 of (item i of textReplaceList))
delay 0.3
keystroke "v" using command down
keystroke "\r"
delay clickDelay
end repeat
end tell
end tell
@neophit
Copy link
Author

neophit commented Dec 23, 2013

Screenshot of Keyboard Text Shortcuts
Screenshot of autocorrect for exponents
Screenshot of autocorrect for fractions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment