SEARCH
TOOLBOX
LANGUAGES
MacOSX

MacOSX

From GarrettHoneycutt

Jump to: navigation, search

Contents

Screensaver Icon

Drag this to your dock to get the screensaver icon

/System/Library/Frameworks/ScreenSaver.framework/Versions/Current/Resources/ScreenSaverEngine.app

Lion aka the worst upgrade experience ever

restore missing ~/Library directory

$ chflags nohidden ~/Library

Do not create ._ metadata files on Mac OSX

Add the following line to your .bashrc or equivalent

export COPYFILE_DISABLE=true

Local snapshots

Disable

$ sudo tmutil disablelocal

Enable

$ sudo tmutil enablelocal

Take a snapshot

$ tmutil snapshot

Sparebundles

Compacting a sparebundle

 $ hdiutil compact -puppetstrings -verbose <path_to.sparsebundle>

Time Machine

The following creates a sparsebundle which Time Machine will automatically use.

Download

#!/bin/bash
#
# 2009-12-27 - Garrett Honeycutt - code@garretthoneycutt.com
#
# Released under GPLv2
#
# Purpose: to create a sparsebundle which Time Machine will use automatically
#
# Usage   : create_time_machine_sparsebundle.sh <destination directory> <size in GB>
# Example : create_time_machine_sparsebundle.sh /Volumes/ExternalHD 100
#
# returns: 0 on success, non-zero on failure
#
# Notes: This is particulary useful if you are using a Drobo or another device
#        that lies about its volume size, so that you can easily grow it later.
#        Without using a sparse bundle, Time Machine would backup more data
#        than the actual disk space. Recommendation for backup size is 2x the
#        amount of data you are backing up.
 
# ensure argument is passed
if [ $# -lt 2 ]; then
    echo "Usage: $0 <destination directory> <size in GB>"
    exit 1
fi
 
DESTDIR=$1
SIZE=$2
 
# get hostname
HOSTNAME=$(/bin/hostname -s)
if [ $? -ne 0 ]; then
    echo "Fail: hostname returned nonzero"
    exit 1
fi
 
# get mac and format appropriately for Time Machine
MAC=$(/sbin/ifconfig en0 | /usr/bin/grep ether | /usr/bin/awk '{print $2}' | /usr/bin/sed -e 's/://g')
if [ $? -ne 0 ]; then
    echo "Fail: finding the MAC address was unsuccessful for en0"
    exit 1
fi
 
# check if the sparsebundle already exists
if [ -d ${DESTDIR}/${HOSTNAME}_${MAC}.sparsebundle ]; then
    echo "Fail: ${DESTDIR}/${HOSTNAME}_${MAC}.sparsebundle already exists"
    exit 1
fi
 
# create the sparse bundle
/usr/bin/hdiutil create -size ${SIZE}g -fs HFS+J -volname "Time Machine Backup" ${DESTDIR}/${HOSTNAME}_${MAC}.sparsebundle
if [ $? -ne 0 ]; then
    echo "Fail: hdiutil returned nonzero"
    exit 1
fi
 
exit 0

Creating an encrypted sparsebundle

#!/bin/bash
#
# 2010-11-08 - Garrett Honeycutt - code@garretthoneycutt.com
#
# Released under GPLv2
#
# Purpose: to create an encrypted sparsebundle
#
# Usage   : create_encrypted_sparsebundle.sh <destination prefix> <size in GB>
# Example : create_encrypted_sparsebundle.sh ~/work 2
#
# returns: 0 on success, non-zero on failure
 
# ensure arguments are passed
if [ $# -lt 2 ]; then
    echo "Usage: $0 <destination prefix> <size in GB>"
    exit 1
fi
 
DEST=${1}.sparsebundle
SIZE=$2
 
# check if the sparsebundle already exists
if [ -d ${DEST} ]; then
    echo "Fail: ${DEST} already exists"
    exit 1
fi
 
# set volume name to be the filename, minus the .sparsebundle bit
VOLNAME=$(basename ${DEST} | awk -F .sparsebundle '{print $1}')
 
# create the sparse bundle
/usr/bin/hdiutil create -encryption -stdinpass -type SPARSEBUNDLE -fs HFS+J -volname ${VOLNAME} -size ${SIZE}g ${DEST}
if [ $? -ne 0 ]; then
    echo "Fail: hdiutil returned nonzero"
    exit 1
fi
 
exit 0

Mounting a sparsebundle

#!/bin/bash
#
# 2010-11-08 - Garrett Honeycutt - code@garretthoneycutt.com
#
# Released under GPLv2
#
# Purpose: to mount a sparsebundle in its current location
#
# Usage   : mount_sparsebundle.sh <path to .sparsebundle>
# Example : mount_sparsebundle ~/work.sparsebundle 
#
# returns: 0 on success, non-zero on failure
 
# ensure arguments are passed
if [ $# -lt 1 ]; then
    echo "Usage: $0 <path to .sparsebundle>"
    exit 1
fi
 
mount_sparsebundle() {
    /usr/bin/hdiutil attach -encryption -stdinpass -mountpoint ${DESTDIR} ${SPARSEBUNDLE}
    if [ $? -ne 0 ]; then
        echo "Fail: hdiutil returned nonzero"
        exit 1
    fi
} # mount_sparsebundle
 
SPARSEBUNDLE=$1
DESTDIR=$( echo $1 | awk -F .sparsebundle '{print $1}' )
 
# check if the directory in which we will mount the sparsebundle exists
# if it does not, create it
if [ ! -d ${DESTDIR} ]; then
    mkdir -p ${DESTDIR}
fi
 
# check if the sparsebundle is already mounted and if so then exit
MOUNTPATH=$( mount | grep "(hfs, local, nodev, nosuid, journaled," | grep test | awk '{print $3}' )
# $MOUNTPATH is empty, so mount the sparsebundle
if [ -z ${MOUNTPATH} ]; then
    mount_sparsebundle
else
    # $MOUNTPATH is not empty and if it does not match the DESTDIR, then mount the sparsebundle
    if [ ${MOUNTPATH} != ${DESTDIR} ]; then
        mount_sparsebundle
    fi
fi
 
exit 0