Mac OSX Tips

Updated: January 14, 2010

Table of Contents:

Scripts

Here are a couple of useful scripts for OSX Snow Leopard. To apply the tweaks open the Terminal application and type the commands below.

Disable horizontal scrolling for Magic Mouse

Very useful if you use Adobe InDesign or Excel often:

defaults write com.apple.driver.AppleBluetoothMultitouch.mouse MouseHorizontalScroll -bool NO

Change the minimum font size in OSX mail

Very useful if you often get HTML mail from Outlook 2003 users with text that look too small:

defaults write com.apple.mail MinimumHTMLFontSize 12

Force sub-pixel antialias in OSX to be always on

OSX sometimes thinks that some newer LCD monitors do not support “LCD Font Smoothing” – using the trick below will force it to be always on like in OSX 10.5 Leopard):

defaults -currentHost write -globalDomain AppleFontSmoothing -int 2

Disable Safari webpage previews

Safari will always save each web page as a JPEG and PNG image to the folder ~/Library/Caches/com.apple.Safari. Not only will this take quite a lot of CPU and disk space, but it’s also a privacy issue since you will have images of your Google calendars etc stored for everyone to view on your hard drive. To disable this feature type the following in the terminal:

defaults write com.apple.Safari DebugSnapshotsUpdatePolicy -int 2

If you later would like to enable saving each web page as a JPEG and PNG image, re-enable this feature by typing the following in the terminal:

defaults delete com.apple.Safari DebugSnapshotsUpdatePolicy

Enable Spotlight within DMG files

If you like me have moved your Mail and Skype folders to an encrypted disk image you also want to add this disk image to Spotlight to enable Spotlight search. The spotlight index is stored on the encrypted volume. To enable Spotlight on a DMG image, mount the DMG image and type the following in the terminal (replace volume_name with the name of your DMG volume).

sudo mdutil -i on /Volumes/volume_name

Screenshots Location

To change the location of your screenshots, enter the following command in the Terminal (replace [path] with a folder location). You need to logout for the change to have effect.

defaults write com.apple.screencapture location [path]

 

SSD Tips

If you have a solid state disk in your mac, here’s a few tips to improve the performance of your computer:

Remove the hibernation image to free gigabytes of storage

By default, Mac OSX will always create a hibernate file that is the same size as your RAM memory, in /var/vm called sleepimage. And every time you close your lid on your laptop, OSX will always save the entire contents of your RAM to this file. If you have an SSD drive in your computer, this will seriously decrease the lifespan of your hard drive. This feature, called “Safe Sleep” can be easily be disabled from the terminal.

First, check the current status of “hibernatemode”. It should be set to “3″:

$ pmset -g | grep hibernatemode
hibernatemode 3

Mode “3″ was introduced in 2005 by Apple, and saves all RAM to the drive every time the computer goes to sleep. Now change it to 0, which means never store RAM memory to the disk (recommended for SSD drives). You can find a full description of all modes here.

$ sudo pmset -a hibernatemode 0

Finally, remove the RAM image stored in /var/vm to free space on your SSD drive:

$ cd /var/vm
$ sudo rm sleepimage

You will now have freed disk space equal to the size of your RAM in your Mac. If you ever return to the new style sleep mode, the sleepimage file will be automatically recreated when you execute the sudo pmset command—yes, it creates the file as soon as you execute the command, not the first time you put the machine to sleep.

Disable the sudden motion sensor (SMS)

if you have an SSD drive, OSX will by default always park the hard drive if the laptop is moved, which is unnecessary if you have an SSD hard drive. Disable the sudden motion sensor by typing:

sudo pmset -a sms 0

Verify that the setting has been applied correctly by typing:

pmset -g

 

Week numbers into iCal / iPhone

If you are using iCal or an iPhone you are probably aware that you can subscribe to various calendars on the web such as national holiday events. One thing missing though is the functionality to show week numbers in the calendar.

Since I use week numbers regularly in my work I need week numbers in my calendar, so I modified a script from MacOSXHints that will create week numbers that can be imported into iCal. What my script does is that it will add an all day event for the first day of the week (Monday in Europe) that shows the current week number.

Open the following page and save it as weeknumbers_2011.ics:

http://www.sanneblad.com/scripts/weeknumbers_2011.php

Double click the file weeknumbers_2011.ics to import the calendar events to iCal. Choose to import the data into a new calendar called “Week numbers” so you can easily hide or remove them if Apple some day should decide to add week numbers to iCal or the iPhone. Done!

Finally – if you want the events in Swedish style (“Vecka 31″) you can use this link instead:
http://www.sanneblad.com/scripts/veckonummer_2011.php

Remove .DS_Store files

If you want to remove hidden .DS_Store files in a folder and do not use a Finder replacement like Path Finder that can show hidden files, you can use the Terminal to easily remove the .DS_Store files using the following command:

find . -name *.DS_Store -type f -exec rm {} \;

The above command searches recursively down for all .DS_Store files and removes them without asking.

Screenshots in OSX

  • Command-Shift-3: Take a screenshot of the screen, and save it as a file on the desktop
  • Command-Shift-4, then select an area: Take a screenshot of an area and save it as a file on the desktop
  • Command-Shift-4, then space, then click a window: Take a screenshot of a window and save it as a file on the desktop
  • Command-Control-Shift-3: Take a screenshot of the screen, and save it to the clipboard
  • Command-Control-Shift-4, then select an area: Take a screenshot of an area and save it to the clipboard
  • Command-Control-Shift-4, then space, then click a window: Take a screenshot of a window and save it to the clipboard

(Snow)Leopard-specific shortcuts:

  • Space, to lock the size of the selected region and instead move it when the mouse moves
  • Shift, to resize only one edge of the selected region
  • Option, to resize the selected region with its center as the anchor point

Better color correction in Firefox

If you use a MacBook, MacBook Pro or MacBook Air, you should be aware that the screen does not have the same color space as a regular SRGB color monitor. In most applications this is not an issue since OSX provides color correction in most applications. Web browsing however is one area where full color correction is not supported (only images tagged with color profile information will be shown properly by default). If you have ever watched a thumbnail of an image that did not look similar to the full image in terms of colors you know what I’m talking about. If you are not with me, you can go to this page to check the differences in your browser between tagged and untagged images:

WEB BROWSER COLOR MANAGEMENT TUTORIAL

The reason colors in web browsers sometimes looks weird is that by default (in Safari and Firefox) color correction is not enabled for images that do not have a color profile embedded. This includes all PNG images and JPG images without EXIF profiles. These images will all look a bit “dull” in colors on a Mac laptop when viewed on the laptop screen. If you would like web images to look like they should, what you can do is:

  1. Install and start Mozilla FireFox
  2. Click the location bar and enter about:config
  3. Search for the value gfx.color_management.mode
  4. Change it’s value from 2 (only color correct tagged images) to 1 (color correct all images)

Now every web image will look right on your Mac laptop screen. Safari does not support color profiling all images, most probably due to the slight performance hit.

For more information, please see: Gfx.color management.mode (Mozillazine)

Optimizing VMware Fusion

If you use VMware Fusion you can switch off System Restore to get extra disk space in Windows XP/Vista/7. On my 32-gb disk image I had 8.6 gb free space after installing Vista + Office 2007 + Visio 2007 + VS 2008. I switched off System Restore and suddenly I had 13.0 gb free space. Much better.

Securing Time Capsule Backups

If you like me use PGP Whole Disk Encryption to protect your Mac you might also have discovered that the Time Capsule backups are stored completely un-encrypted. This means if someone steals your Time Capsule disk they will get full access to all your emails and files, even if you have encrypted your system disk. Based on some old tips I have found on the web I have put together below a complete guide on how to encrypt and decrypt Time Capsule backups so you can use them both for backup as well as restore.

Encrypt  Backups

  • Set up Time Machine to back up to an AFP drive (Time Capsule or shared network disk).
  • Let Time Machine start backing up, then stop the back up. This will have created <machine_name>.sparsebundle on the AFP drive.
  • Disable Time Machine.
  • Open a Terminal and run these commands:
    $ cd /Volumes/<AFP Drive>/
    $ mv <machine_name>.sparsebundle <machine_name>-old.sparsebundle
    $ hdiutil convert -format UDSB -o <machine_name>.sparsebundle -encryption AES-256 <machine_name>-old.sparsebundle
  • It will ask you for a password. Type in a long password you won’t forget.
  • Double click the sparsebundle in the Finder UI. You will be prompted for your password. Type that in and tick the “Remember password” check box.
  • Open /Applications/Utilities/Keychain Access and find <machine_name>.sparsebundle. Right click it and select Copy <machine_name>.sparsebundle.
  • Select System Keychain on the left hand side of Keychain Access and paste it in the main area. Allow this action if you are asked. Remember to lock the System Keychain when you are done.
  • If you use Mac OSX 10.6 Snow Leopard, you also need to do one last thing. Open the contents of both sparsebundles (in the Finder, right-click on the sparsebundles, “Show Package Contents”). Then move the file “com.apple.TimeMachine.MachineID.plist” from the old sparsebundle to the new one.
  • Remove <machine_name>-old.sparsebundle and start Time Machine again.

Decrypt Backups for Restore

If you need to restore your backup you first need to decrypt the Time Machine backup. You do this using:

  • Mount the AFP drive on a working Mac computer (Time Capsule or shared network disk).
  • Open a Terminal and run these commands:
    $ cd /Volumes/<AFP Drive>/
    $ mv <machine_name>.sparsebundle <machine_name>-old.sparsebundle
    $ hdiutil convert -format UDSB -o <machine_name>.sparsebundle <machine_name>-old.sparsebundle
  • If you use Mac OSX 10.6 Snow Leopard, open the contents of both sparsebundles (in the Finder, right-click on the sparsebundles, “Show Package Contents”). Then move the file “com.apple.TimeMachine.MachineID.plist” from the old sparsebundle to the new one.
  • Boot your new Mac computer and choose Restore from Backup. It should find your Time Machine backup and be able to restore properly.

8 thoughts on “Mac OSX Tips

  1. Thanks JorisX, I didn’t know about that one! I will still continue adding them my way though since I need them synced to my iPhone. But it was an interesting approach to change the date format on the system.

  2. Your way to remove .DS_Store files will result in an error:
    %find . -name *.DS_Store -type f -exec rm {} \;
    find: No match.

    The correct way to remove .DS_Store files:
    %find . -name ‘*.DS_Store’ -type f -exec rm ‘{}’ \;

    Tho its not smart to remove .DS_Store files from your Mac OS X file system since you also remove meta data that has been saved to the .DS_Store file.

    In case you want to clear out the ._meta_resource files, use the following:
    %dotclean

    This is a default Mac OS X command for 10.6 which cleans out these files.
    Again, keep in mind that you don’t do this on a mounted file system that is NOT HFS+ since this will result again in loss of your meta data.

    Another thing, watch out with enabling spotlight for DMG files, lets say you have an install directory containing different installation files that might be quite large (xcode, >2GB) can result into a really slow response of Spotlight and it slows your Mac down a lot while scanning the DMG files.

    This is my 50 cent addition to your blog, keep on going :-)

  3. Hi Marius,

    About DS_Store: Very weird.

    If I type like I wrote on this page:
    find . -name *.DS_Store -type f
    I get a list of all .DS_Store files. It works just fine for me on Mac OSX 10.5 and 10.6.

    If I instead type like you suggested:
    find . -name ‘*.DS_Store’ -type f
    I get no results

    Regarding Spotlight. What I use it for is to enable searching within a specific DMG file, not all DMG files. In my case I store my Mail data, Adium and Skype data inside an encrypted DMG file and have linked the regular folders to folders within this DMG file. To be able to search emails then in Mail I have to enable Spotlight indexing inside this specific DMG file. So my tip won’t enable Spotlight to index all DMG files, it will just enable indexing of a specific DMG file used for user data.

    Cheers
    Johan

  4. Oh, my bad Johan…

    find . -name .DS_Store -type f

    This should do the trick, the asterisk is not needed since the file starts with a dot, also you do not have to quote the name. This is only required if you use the asterisk.

  5. Pingback: SSD Tips

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>