Last active
January 5, 2025 02:58
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Author
neophit
commented
Dec 23, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment