A shell control script for PowerMate

Jan 03, '08 07:30:00AM

Contributed by: benholt

I got a PowerMate for my birthday this year, and immediately tried it out with AppleScript. I wrote a small shell control script for the device that seems to work with any version of the software (I happen to be using 1.5.1, which is the out-of-the-box version). Here's the code:

#!/bin/sh

showMenu() {
	echo "-----------------"
	echo "PowerMate Control"
	echo "-----------------"
	echo
	echo "pulse x	= Pulse at x rate, from 0-100."
	echo "on x	= Device stays on with brightness x, from 0-100."
	echo
	echo "These two settings are mutually exclusive."
}

if [ $# = 0 ]; then
    showMenu;
fi

arg=$1

if [ "$arg" = "pulse" ]; then
	num=$2
	
	realnum=`echo "scale=0; ($num * 20) / 100" | bc`
	
	osascript -e 'tell application "PowerMateDriver" to set pulse always to true'
	osascript -e "tell application "PowerMateDriver" to set pulse rate to $realnum"
fi

if [ "$arg" = "on" ]; then
	num=$2
	
	realnum=`echo "scale=0; ($num * 255) / 100" | bc`
	
	osascript -e 'tell application "PowerMateDriver" to set pulse always to false'
	osascript -e "tell application "PowerMateDriver" to set brightness to $realnum"
fi
To use, put the script in your $PATH, chmod it to 755, and invoke with the command line.

Note that this script is more of a resource hog than other applications that change the Powermate settings dynamically (MenuMeters, Cee Pee You), probably because of the AppleScript/shell scripting used. But this script could be useful to many of those who want an easy way to interface with the device with any number of programs.

[robg adds: Not having a PowerMate, I don't have any way to test this one (nor am I sure what it does!).]

Comments (3)


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