Sunday, October 12, 2008

Toggle grayscale display on OS X with this AppleScript

I was looking for something that would give my mother a few more months of computer use. The OS X grayscale accessibility option looked interesting, but there's no keyboard shortcut for this option.

I thought I could record an AppleScript shortcut, but the accessibility pane is not scriptable. (Apple had, I think, a reasonable accessibility record with Mac Classic, but they tossed that out with OS X. They've been notably half-hearted for years, but some recent threats from Massachusetts may inspire future improvements.).

Apple recommends using System Events, but that's way beyond my limited AppleScript skills. I've made several stabs at figuring out AppleScript, but the damned language just annoys me. I wish they'd deprecate the original and adopt Python's syntax, scoping, etc.

But I digress.

Baltwo, a generous Apple forum poster [1], has written a post with the AppleScript System Events script I was looking for. It works in 10.5.5 ...
Apple - Support - Discussions - Keyboard shortcut to switch between ...

tell application 'System Preferences' to activate
delay 1
tell application 'System Events'
tell process 'System Preferences'
click the menu item 'Universal Access' of the menu 'View' of menu bar 1
click the radio button 'Seeing' of the first tab group of window 'Universal Access'
click the checkbox 'Use grayscale' of tab group 1 of window 'Universal Access'
end tell
end tell
tell application 'System Preferences' to quit"
The script, of course, will break with significant UI changes to the Universal Access pain. It works for now, I'll test it out with 10.4.11 though I think some of the System Events scripting might require 10.5.

Apple has greatly improved their AppleScript support site by the way. I've thought for years that AppleScript would go the way of OS X Services, but it continues on.

[1] You can now "subscribe" to users, and I've "subscribed" to his posts. I wonder sometimes if these are real people, or pseudonyms for Apple employees. written a very large number of forum posts.

No comments:

Post a Comment