Mac OS X Tips

This page provides tips of Mac OS X such as useful commands for your work. We believe these tips might be useful for Mac OS X users and engineers who use Mac OS X.

For other tips, please go back to tips top page.

Search from the Internet:
Custom Search

Mac OS X Generic Tips

Useful commands on Mac OS X

Locate database

In some unix-like operating systems, a periodic batch script maintains a locate database by default. However, Mac OS X does not. To create the locate database and maintain it periodically, you can execute the following command:

$ sudo launchctl load -w /System/Library/LaunchDaemons/

Note that the file /System/Library/LaunchDaemons/ defines the update period of the locate database, so you can change some parameters if you need. By default, the locate database would be updated every week (3:15 AM, Sat.).

Scanning IEEE802.11 wireless networks

IEEE802.11 wireless networks can be scanned by the following command:

$ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s

If you want to know detailed information on what you are connecting to, type the command with option -I:

$ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I

When you want to sniff IEEE802.11 traffic, type the following command:

$ sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport <interface> sniff <channel>

Turning on/off SOCKS proxy via (or your shell)

To turn on the socks proxy for Ethernet or AirPort, execute the following command:

$ networksetup -setsocksfirewallproxystate <Ethernet|AirPort> on

To turn off it, do as follows:

$ networksetup -setsocksfirewallproxystate <Ethernet|AirPort> off

You can check the current status of your proxy setting by the following command:

$ networksetup -getsocksfirewallproxy <Ethernet|AirPort>

Please note that the interface name “AirPort” might be “Wi-Fi” on Mac OS X Lion (10.7).

Configuring nameservers via (or your shell)

In *BSD/Linux operating systems, nameservers are generally configured in the file /etc/resolv.conf However, in Mac OS X, this setting conflicts that of Network Preferences, and consequently, we need to use an alternative. The following command is to obtain current nameserver configuration:

$ networksetup -getdnsservers <Ethernet|AirPort>

To set new nameserver(s), type as follows:

$ networksetup -setdnsservers <Ethernet|AirPort> <nameserver's IP address>

To delete the manual configuration (i.e., to reset DNS configuration) you can use the keyword empty:

$ networksetup -setdnsservers <Ethernet|AirPort> empty

Launching TFTP server

Mac OS X has a TFTP server software, but it is disabled by default. You can launch the TFTP server as follows.

$ sudo launchctl
launchd% load -F /System/Library/LaunchDaemons/tftp.plist

You can stop the TFTP server by the following command.

$ sudo launchctl
launchd% unload /System/Library/LaunchDaemons/tftp.plist

The default root directory is /private/tftpboot, and you can change this root directory by editing an entry with key "ProgramArguments" in /System/Library/LaunchDaemons/tftp.plist. Other options can be used by adding arguments there. You can find details of the options at a man page of tftpd(8).

Note that you must give write permission for others to files onto which you overwant to write contents from tftp clients.

Launching screensaver, falling into sleep, or going to login window from your Terminal

To launch screensaver from your terminal, you can use the following command (AppleScript).

$ osascript -e 'tell application id "" to launch'

If you want to make your Mac OS X sleep from your terminal, you can use the following command (AppleScript).

$ osascript -e "tell Application \"System Events\" to sleep"

To go to login window (i.e., lock your screen) from your terminal, you use the following command; N.B., it takes several seconds, unlike "Lock Screen" from KeyChain.

$ /System/Library/CoreServices/Menu\ Extras/ -suspend