The Lumber Room

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

Flashing the screen on Mac OS X

with one comment

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:
    time.sleep(1)
    t = datetime.datetime.now()
    if t.minute % 15: continue
    if last==None or (t-last).seconds >= 60:
        last = t
        print "Flashing at ", t
        s = do(['./brightness', '-l']).stdout.read()
        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 , , , ,

One Response

Subscribe to comments with RSS.

  1. doesn’t work anymore

    ithihasm

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


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s