Many people keep lists of OS 9’s features they still await for OS X. For the most part, I’m not one of these people. However, as a PowerBook user, the lack of a fully featured Location Manager is rather irritating. Locations in OS X only modify network settings, whereas this little-used OS 9 feature allowed you to change your default printer, sharing prefs, localization prefs, and energy saver prefs.
Energy Saver is the big one for me. Moreso than my previous PowerBooks, settings in Energy Saver can make a big difference in how long my battery lasts and how hot my machine gets. Having to go into System Preferences, every time, is a moderate pain.
Enter pmset and Script Menu. If you’re not already using Script Menu, you’re really missing out. For now, just jump into /Applications/AppleScript and run the Install Script Menu script. You’ll get a little scroll in your menu bar allowing you to quickly run any script in, among other places, ~/Library/Scripts. The lovely thing about Script Menu is that it doesn’t only run AppleScripts – it can run shell scripts, too.
I created several scripts that begin with PM- and used pmset to create some presets.
asterope:~/Library/Scripts jc$ cat PM-HIGHEST
#!/bin/sh
pmset -a dps 0 reduce 0 acwake 0 lidwake 1
asterope:~/Library/Scripts jc$
The only bummer is that pmset can only be run by root. So, in order for Script Menu to run the command, we’ll need to set the file to be owned by root and run suid root as well.
asterope:~/Library/Scripts jc$ sudo chown root:jc PM-HIGHEST
Password:
asterope:~/Library/Scripts jc$ sudo chmod u+sx PM-HIGHEST
asterope:~/Library/Scripts jc$
Check out man pmset for a full description of the various settings you can perform.
You might take a look at Location X.
Perhaps not as fun as mucking around in Terminal, but a very slick utility nonetheless.
—
“I love my Mac. I feel about it what no man should feel about a computer.” – Jeffery Zeldman
—
“I love my Mac. I feel about it what no man should feel about a computer.” – Jeffery Zeldman
Location X is nice, indeed… but the pricetag of $20 is a bit steep for something I can do via Script Menu for free. I’ve long held that System Utility type Shareware really, really needs to be priced at $5 or so.
Instead of setting the suid flag on your files use the follow code example to prompt for a password when you execute the shell (fix the tabs yourself):
#!/bin/sh
if [ $USER = ‘root’ ]; then echo ‘I am root! Put your root script here!’
else osascript -e “do shell script \”$0\” administrator privileges true altering line endings false”
fi
Well the PRE tag is banned and CODE tag doesn’t work right. I’ll post it to my blog with proper formatting: http://toxicsoftware.com/blog/
Thanks for taking the time to contact an admin …
Fixed it.
—
cp
So, I edited the script to the following:
#!/bin/sh
if [ $USER = ‘root’ ]; then
pmset -a dps 0 reduce 0 acwake 0 lidwake 1 dim 0 spindown 0
else
osascript -e “do shell script \”$0\” administrator privileges true altering line endings false”
fi
Oddly, it asks for an admin password, then executes pmset as root regardless of the password entered. I tested this by modifying my script to have only the pmset command and selecting it from Script Menu. Afterwards, ran pmset -g and verified that my settings were not changed.
Then, changed the script to the above code. Selected from Script Menu. Entered a bogus admin password. Executed pmset -g again. Settings were changed.
WTF.
aha. it uses sudo so, if you’ve authed in the last few minutes, it executes your code even if you just now entered a bad password.
Well, that just screams ‘secure’ to me. The opposite would also be true (untested) where you use the AppleScript and then sudo’s home-free in Terminal for five minutes. Lovely.
I seem to recall one of the older Security Updates supposedly fixing that?
—
cp