The Lumber Room

"Consign them to dust and damp by way of preserving them"

Flashing the screen on Mac OS X

with 2 comments

Here’s one way. There’s a C program to adjust the screen’s brightness written by Nicholas Riley, also available from this blog post by Matt (Danger) West. Get it. The rest is obvious. For instance, here’s a Python script, which should have probably been written in Perl:

import os, re, time

s = os.popen('./brightness -l').read()
ob = re.findall('brightness (\d.\d+)', s)[0]

w = 0.2
for i in range(10):
    os.system('./brightness 0'); time.sleep(w)
    os.system('./brightness 1'); time.sleep(w)
    if(i==4): os.system("say beep")

os.system('./brightness ' + ob)

Tune parameters to avoid epileptic seizures.

Or, to flash screen and say “beep” every 15 minutes:

#!/usr/bin/env python

import datetime
import re, time, subprocess

def do(cmd): 
    return subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

last = None
while True:
    t =
    if t.minute % 15: continue
    if last==None or (t-last).seconds >= 60:
        last = t
        print "Flashing at ", t
        s = do(['./brightness', '-l'])
        brightnesses = re.findall('brightness (\d.\d+)', s)
        if not brightnesses: continue
        ob = brightnesses[0]
        for i in range(6):
            do(['./brightness', '0']); time.sleep(0.2)
            do(['./brightness', '1']); time.sleep(0.2)
            if i==3: do(['say', 'beep'])
        do(['./brightness', ob])

Written by S

Mon, 2009-08-17 at 16:07:05

Posted in compknow

Tagged with , , , ,

2 Responses

Subscribe to comments with RSS.

  1. doesn’t work anymore


    Mon, 2016-03-21 at 06:51:24

    • Still works for me (macOS Sierra, 10.12.6).


      Sat, 2017-09-30 at 16:19:00

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: