Cycle between bases in Programming Calculator mode

Sep 08, '11 07:30:00AM

Contributed by: ob1cannoli

I use the Programming mode in Calculator.app and often find myself moving to the mouse to switch between octal, hex, and decimal modes. I wrote the two following Applescripts to cycle forward and backward between bases and use Butler to bind them to Command+D and Command+Shift+D.

Cycle forwards:

tell application "System Events"
  tell application process "Calculator"
    repeat with i from 1 to 3
      if the value of radio button i of radio group 1 of group 2 of window "Calculator" is 1 then
        click radio button ((i mod 3) + 1) of radio group 1 of group 2 of window "Calculator"
        exit repeat
      end if
    end repeat
  end tell
end tell
Cycle backwards:
tell application "System Events"
  tell application process "Calculator"
    repeat with i from 1 to 3
      if the value of radio button i of radio group 1 of group 2 of window "Calculator" is 1 then
        if i is equal to 1 then
          set n to 3
        else
          set n to i - 1
        end if
        click radio button n of radio group 1 of group 2 of window "Calculator"
        exit repeat
      end if
    end repeat
  end tell
end tell

[crarko adds: I tested this (on 10.7.1), and it works as described.]

Comments (0)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20110901094355728