Skip to content

Instantly share code, notes, and snippets.

@OKsign
Last active May 31, 2018 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OKsign/a42ed5d0e4cccdd0b17c99412734d50d to your computer and use it in GitHub Desktop.
Save OKsign/a42ed5d0e4cccdd0b17c99412734d50d to your computer and use it in GitHub Desktop.
-- user input (from 1 to 21)
set SmallSize to 3
set BigSize to 15
-- end of user input
-- tested version: System Preferences 14.0
try
if application "System Preferences" is running then
set prefRunning to 1
else
set prefRunning to 0
end if
set Scale to {1.0, 1.15, 1.3, 1.45, 1.6, 1.75, 1.9, 2.05, 2.2, 2.35, 2.5, 2.65, 2.8, 2.95, 3.1, 3.25, 3.4, 3.55, 3.7, 3.85, 4.0}
set uSmall to item SmallSize of Scale
set uBig to item BigSize of Scale
tell application "System Preferences"
activate
delay 0.3
repeat 300 times
tell application "System Events"
set activeApp to (get name of first process where it is frontmost)
if activeApp is "System Preferences" then
exit repeat
end if
end tell
end repeat
tell application "System Events"
keystroke "l" using command down
end tell
delay 1
set current pane to pane "com.apple.preference.universalaccess"
repeat 300 times
set winName to get name of front window
if winName is "Accessibility" then
exit repeat
end if
end repeat
delay 1
tell application "System Events"
key code 48
delay 0.03
repeat 20 times
if slider "Cursor size:" of window "Accessibility" of process "System Preferences" exists then
exit repeat
else
delay 0.03
key code 126
end if
end repeat
end tell
delay 1
tell application "System Preferences"
tell application "System Events"
set SizePref to get value of slider "Cursor size:" of window "Accessibility" of application process "System Preferences"
delay 0.3
end tell
end tell
end tell
end try
roundThis(SizePref, 2)
on roundThis(n, numDecimals)
set x to 10 ^ numDecimals
tell n * x to return (it div 0.5 - it div 1) / x
end roundThis
set SizePref to result
try
tell application "System Preferences"
tell application "System Events"
repeat 1 times
if SizePref = uBig then
set value of slider "Cursor size:" of window "Accessibility" of application process "System Preferences" to uSmall
delay 0.02
exit repeat
end if
if SizePref = uSmall then
set value of slider "Cursor size:" of window "Accessibility" of application process "System Preferences" to uBig
delay 0.02
exit repeat
end if
if SizePref < uSmall then
set value of slider "Cursor size:" of window "Accessibility" of application process "System Preferences" to uSmall
delay 0.02
exit repeat
end if
if SizePref > uSmall then
set value of slider "Cursor size:" of window "Accessibility" of application process "System Preferences" to uBig
delay 0.02
exit repeat
end if
end repeat
end tell
end tell
delay 1
if prefRunning = 1 then
tell application "System Events"
key code 33 using command down
delay 0.03
key code 33 using command down
end tell
else
tell application "System Preferences"
quit
end tell
end if
end try
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment