macosx | arfore dot com

I have been updating my wallpaper to a new monthly desktop wallpaper from the Smashing Magazine site for several months.

With earlier versions of Mac OS X it was easy to update all spaces at once because the default change action affected all the spaces. With the advent of Mac OS X 10.7 (aka Lion) each space is capable of having a unique wallpaper. While this is a neat feature, there is no option to apply the change to all the spaces. One workaround is to manually change each space.  Another workaround is remove all your spaces, make the change then add the spaces back.

Neither of these options is suitable to me. The first option is fairly cumbersome, and the second will undo my application-to-space bindings. To solve this problem I have written a script than handles it.

Here’s the script:

#!/bin/bash
 
# Simple Script to update the desktop wallpaper
# background for all desktop spaces in Mac OS X 10.7
#
# Usage: update_desktop_wallpaper.sh old_wallpaper_path new_wallpaper_path
#
# Andy Fore
# http://arfore.com
 
# Check for command line arguments
if [ -z "$1" ]; then
    echo "Usage: update_desktop_wallpaper.sh old_wallpaper_path new_wallpaper_path"
    exit 1;
else
    # Change location to the active user preferences directory
    cd ~/Library/Preferences
 
    # Backup the original plist file
    echo "Making a backup of the original plist file..."
    cp com.apple.desktop.plist com.apple.desktop.plist_backup
 
    # Convert the desktop plist from binary to xml
    echo "Converting plist file to text format..."
    plutil -convert xml1 com.apple.desktop.plist
 
    # Update the desktop wallpaper file location/name
    echo "Editing the file..."
    sed -i "" "s/$1/${2}/g" com.apple.desktop.plist
 
    # Convert the desktop plist back to binary format
    echo "Converting plist file back to binary format..."
    plutil -convert binary1 com.apple.desktop.plist
 
    # Killing Dock process
    echo "Sending the kill signal to the Dock process to force reload of plist"
    killall -HUP Dock
 
    # Display completion message
    echo "Operation now complete."
fi

Example

$ ./update_desktop_wallpaper.sh June2012_Calendar.jpg July2012_Calendar.jpg

Note that I only used a filename in the example. This is because all of my calendar wallpapers are saved in the same directory path, making the unique part just the filename itself.

Changing the default editor on Dreamhost | arfore dot com

While setting up the cronjob for auto archiving data on my Piwik installation, I found that the default editor for Dreamhost shell accounts is set to use joe (Joe’s Own Editor). While this is a nice editor for many users, it is not as familiar to me as using vim, the opensource vi clone.

Combing through the Dreamhost wiki, I found the line in the crontab wiki article talking about exporting the editor setting by adding an entry in the .bashrc file in the root of your account.  This information may have been accurate at one point, but now the shell accounts are configured to use .bashrc for the non-interactive logins and to use .bash_profile for the interactive logins.

So to update you editor on your shell account you need to add the following line to the .bash_profile file:

export editor="/usr/bin/vim"

or

export editor="/usr/bin/vi"

If you prefer to use emacs, you can change the line to be:

export editor="/usr/bin/emacs"