I am writing a script and I need to figure out current key codes for brightness up and down with an external keyboard.

I know the standard for a MacBook is 107 and 113, though as soon as I connect a different bigger apple keyboard, those changes to 145 and 144.

I need to be able to get this information out of the terminal as I'm scripting things there.

Is this possible?


The 'System keys' don't seem to have a Key Code equivalent, they are actioned below the OS-level. Try Key Codes (freeware)


Simply save these lines (first one makes your screen darker, second one brighter) in one Applescript .scpt file each:

tell application "System Events" to key code 107

tell application "System Events" to key code 113

and execute them with

/usr/bin/osascript /path/to/the/script
  • Yeah, the problem is that the key code is not the same with an external keyboard for example, read my question again. – andreasg May 21 '15 at 8:18
  • Oops, sorry, I'll update my answer once I get ahold of my external keyboard. – Asmus May 21 '15 at 8:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .