Wednesday, June 28, 2006

Systemsetup and Networksetup

A couple of useful command-line utilities come bundled with Apple Remote Desktop (ARD). They can be used whether you're using ARD or not, and give you a convenient way to change some of OS X's defaults. The utilities are "systemsetup" and "networksetup", but you probably won't find either of them in your search path. They live under /System/Library/CoreServices in the directory RemoteManagement/ARDAgent.app/Contents/Support, where you'll find them with names like "systemsetup-panther" or "systemsetup-tiger". If you've ever enabled ARD (even if you've turned it off again later), you'll find that this directory also contains two symbolic links named "systemsetup" and "networksetup", which point to an apropriate "cat-named" version of each program.

With systemsetup (see the man page here), you can control or view a lot of the same settings that are available in the graphical "System Preferences" tool. For example, the command:
systemsetup -setsleep off

will disable power management for disks, display and CPU. The separate parameters "-setcomputersleep", "-setdisplaysleep" and "-setharddisksleep" can be used to turn power management on/off for each. Specifying a number of minutes instead of "off" will turn power management on. (These settings can also be changed by editing /Library/Preferences/SystemConfiguration/com.apple.PowerManagement.plist, but systemsetup provides a convenient interface that will -- presumably -- be independent of future structural changes in the plist file, and so can safely be used when developing scripts.)

Other examples, from the man page, are:

systemsetup -setdate 04:15:02
systemsetup -settime 16:20:00
systemsetup -settimezone US/Pacific
systemsetup -setnetworktimeserver time.apple.com


With networksetup (see the man page), you can configure or view network settings. For example, the command:

networksetup -getcomputername

will do the obvious. The command "networksetup -listallhardwareports" will show something like this:

Hardware Port: Bluetooth
Device: Bluetooth-Modem
Ethernet Address: N/A

Hardware Port: Built-in Ethernet
Device: en0
Ethernet Address: 00:16:cb:00:00:00

Hardware Port: Built-in FireWire
Device: fw0
Ethernet Address: 00:16:cb:ff:00:00:00:00

Hardware Port: AirPort
Device: en1
Ethernet Address: 00:16:cb:00:00:00

and "networksetup -getmacaddress en0" will return the wired network interface's MAC address.

Obviously, these commands only give access to a subset of the system's configuration parameters, but they're handy for many tasks.

No comments: