Macos X for unix geeks

There are many articles documenting the command line of OSX, many of these articles cover the basics that unix geeks are already familiar with, command line completion, ls and it's arguments, permissions and directories.

Few of these articles cover the Macos X specific commands that can make OSX command life easier.

asr

asr is the software restore tool, it can install onto a blank disk from a diskimage. The diskimage can be made with the hdiutil command where the ource directory is /

asr restore --source backup.dmg --target /Volumes/NewDisk

A diskimage can also be another disk volume, for backing up one entire volume to another (like carbon copy cloner for you mac people)

asr restore --source /Volumes/OldVolume --target /Volumes/NewDisk

Once a diskimage is created it must be indexed using the asr imagescan command.

asr imagescan --source backup.dmg

cgsession

CGsession

Lock screen
/System/Library/CoreSerices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend

CGSession also supports the -switchToUserID option to switch to another user, but I've never used this command.

disktool

disktool is used for mounting and unmounting disks.

Unmount a disk (not eject) useful when using unix tools that require direct access to the disk device, such as cdrdao.
disktool -u disk2

Eject a disk
disktool -e disk2

Mount a disk (when a disk has been unmounted but not ejected)
disktool -m disk2

diskutil

diskutil is used mostly for preparing or erasing disks. Some of it's functionality seems to overlap with hdiutil but the most useful features are;

erasing and partitioning a disk
diskutil erasedisk "Journaled HFS+" MyNewDiskname disk2

Formatting a device with FAT for sharing with a windows machine:
diskutil erasedisk "MS-DOS FAT32" NEWDISK MBRFormat disk3

(FAT doesn't support case preserving volume names)

listing attached disks and partitions
diskutil list

drutil

drutil is used for manipulating cd media. Can erase RW disks both quickly and fully. Can display the type and length of media inserted. Can also burn directories to disk. (this may be a leopard feature as I never remembered this before)

Burning a directory (leopard only)

drutil burn dir

Burning an audio disk (leopard only)

drutil burn -audio music.aac

Getting information about blank media

drutil discinfo

For more useful information

drutil status

 Vendor   Product           Rev 
 PIONEER  DVD-RW  DVR-110D  AA06

           Type: DVD-R                Name: /dev/disk3
   Write Speeds: 4x, 6x, 8x, 12x, 16x
   Overwritable:  510:46:46         blocks:  2298496 /   4.71GB /   4.38GiB
     Space Free:  510:46:46         blocks:  2298496 /   4.71GB /   4.38GiB
     Space Used:   00:00:00         blocks:        0 /   0.00MB /   0.00MiB
    Writability: appendable, blank, overwritable
      Book Type: DVD-R (v5)
       Media ID: MCC 03RG20

Open or close the tray

drutil tray open

drutil tray close

hdid

hdid appears to be an alias for hdiutil attach. It's a bit quicker than typing hdiutil attach.

hdiutil

hdiutil is mostly used for manipulating disk images the most useful thing s it can do are;

Burn CDs (from a discimage)
hdiutil burn discimage.iso

Make disk images
hdituil create -srcfolder ~/Documents documents.dmg

Mount disk images
hdiutil attach documents.dmg

installer

Installer is the software installation tool that can install .pkg or .mpkg

installer -pkg CoolApp.pkg -target /

the -verbose option allows some visibility to what is being done.

osascript

osascript, is probably the most useful of all that I've come across, it allows access to apple script to control applications running on the machine, it's another scripting language but I find the language a little difficult to understand, as it's all about message passing and telling an application what to do, no telling the window of the application what to do. no wait, telling the document of the window of the application what to do. I'm not going into apple script here.

The script is entered on the command line with the -e option:

osascript -e 'tell application "eyetv" to get recordings'

pdisk

pdisk is the partitioning utility, It's only useful for low level editing of the partition table since diskutil can batch create a partition table when erasing a disk.

pdisk needs to be run as root, to have write access to the disk block device. It has a menu system similar to fdisk under linux and isn't difficult to work out.

sudo pdisk /dev/disk0

screencapture

screencapture can save the whole screen or a single window to a file.

capture the whole screen
screencapture screen.png

capture one window, selectable by the mouse (which turns into a camera)
screencapture -iW window.png

sips

sips is an image conversion and manipulation program. It can be used to convert from one format to another, including PDF. It can rotate and scale. I've seen it available in 10.3.9.

To scale an image to maximum dimensions of 752 (both horizontal and vertical) while preserving the aspect ratio use: sips -Z 752 image.jpg
The above will also overwrite image.jpg.

to write to another file use: sips -Z 752 image.jpg --out imageScaled.jpg

I am uncertain what jpeg quality it uses by default, to specify a jpeg quality of 50 use: sips -Z 752 image.jpg --setProperty formatOptions 50 --out imageScaled.jpg

An image format can also be specified with the --setProperty format: sips image.jpg --setProperty format png --out image.png

Image details can also be queried with: sips image.jpg --getProperty all