Mac OS X Tips
Useful commands on Mac OS X
- Open a certain directory in Finder
$ open <path-to-directory>
- Open a certain application
$ open -a <name-of-application>
- Copy a content of a file to clipboard
$ cat <path-to-file> | pbcopy
- Paste text in clipboard to a file
$ pbpaste > <path-to-file>
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/com.apple.locate.plist
Note that the file /System/Library/LaunchDaemons/com.apple.locate.plist 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.).
Enabling IPv6 temporary address on Mac OS X
On Mac OS X (of version <=10.6.4, as far as we know), IPv6 temporary address is disabled by default. From the point view of privacy, it may be recommended to use temporary address instead of EUI-64 IPv6 address because EUI-64 IPv6 address, which is automatically generated from MAC address, reveals the hardware identity (i.e., MAC address).
- To enable IPv6 temporary address on your Mac OS X,
type the following command:
$ sudo sysctl -w net.inet6.ip6.use_tempaddr=1
- To enable it on boot, add the following line
Background image on login screen
As far as we know as of August 2010, we cannot change the background image on login screen (just after startup) via "System Preferences.app". We can change it by replacing the file /System/Library/CoreServices/DefaultDesktop.jpg by your preferred JPEG file.
Optimizing Mail.app on Mac OS X
The Mail.app on Mac OS X started to use sqlite for its mail indexing from one version; I'm not sure about the date/version, but it was maybe from Leopard or Snow Leopard of Mac OS X. We confirmed this with Version 4.3 (1081) of Mail.app.
Sqlite makes cache etc., and consequently, we should periodically run vacuum command not to make it slow, as follows:
- Quit Mail.app
- Open database with sqlite:
$ sqlite3 ~/Library/Mail/Envelope\ Index
- Run vacuum command:
sqlite> vacuum subjects;
- Exit from sqlite CLI:
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 Terminal.app (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>
Configuring nameservers via Terminal.app (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.