Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can I make a program on my Mac that when activated will automatically press two keys in sequence repeatedly?

Strange request, but for my Mac to work the brightness down and brightness up keys must be constantly toggled.

share|improve this question
up vote 0 down vote accepted

This is the cleanest/easiest way I can think of:

Go to:, scroll to the bottom, and download the precompiled binary. Unarchive and place it in your Applications folder (/Applications)

After you have that placed, open Applescript editor and type:

do shell script "/Applications/brightness 0.9"
delay 0.5
do shell script "/Applications/brightness 1"
delay 0.5
end repeat

Export that wherever you want as an app.

When you launch it, it should quickly fluctuate your brightness.

It's a lot less glitchy if you go to System Preferences>Displays>Display and uncheck "Automatically adjust brightness."

share|improve this answer

Does your brighness change unexpectedly? Then Go in "System Preferences", and then the "Display" section, and untick the "Automatically adjust brightness as ambient light changes" option.

share|improve this answer

AppleScripts can't simulate pressing the media keys. Otherwise something like this might work:

    tell application "System Events"
        delay 1
        key code 122 -- F1
        delay 1
        key code 120 -- F2
    end tell
end repeat

I also tried changing other key combinations to the brightness keys with KeyRemap4MacBook, but it doesn't affect the key code or keystroke commands.

Keyboard Maestro can simulate pressing the media keys (even though they are shown as question marks):

You can run the action every minute by adding this to crontab:

* * * * * osascript -e 'tell app "Keyboard Maestro Engine" to do script "test"'

Another option might be to run brightness.c with cron or launchd.

share|improve this answer
In other words, remap brightness controls to F1/F2 first using KR4M, then run this AppleScript? – Daniel Beck Dec 31 '12 at 16:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.