Command Line Mounting AFP over SSH with Spaces in the Shared Folder Name

I couldn’t find an exact example of my implementation to mount an AFP share over SSH on my Mac, especially when the share has spaces in the shared folder name. I had seen a couple posts on forums that mention url-encoding the spaces, but since I’m on the command line, I often think of escaping spaces with a backslash. Well it turns out that url-encoding a space with %20 makes it work and here’s a little script I run to mount remote AFP shares:

umount "/Volumes/Share With Spaces In Folder Name" # unmount any stale shares
rmdir "/Volumes/Share With Spaces In Folder Name" # remove any stale sharepoints
pkill ssh -NfL 5548:127.0.0.1:548 username@domainname.tld # kill any ssh sessions with specific port redirections
ssh -NfL 5548:127.0.0.1:548 username@domainname.tld # ssh and port redirect into your remote system
mkdir "/Volumes/Share With Spaces In Folder Name" # create a new sharepoint
mount_afp afp://username:password@localhost:5548/Share%20With%20Spaces%20In%20Folder%20Name /Volumes/Share\ With\ Spaces\ In\ Folder\ Name

With this method I realize that my password is in the clear on the command, but since it’s mounting on my system to a port that is tunneling ssh, the password is encrypted in the transmission request so therefor not technically transmitted in the clear across the internet.

Time Machine Auto-mount/unmount Drive OS X

Here’s a way to avoid having to manually mount and unmount (eject) a USB backup drive before and after a Time Machine backup on OS X Lion or later by using a shell script and creating a LaunchAgent.

I have a USB backup drive connected through my monitor to my Macbook Pro and I often find myself wanting to quickly unplug and go without the consequences of the drive not being ejected properly. As well, I need the drive to be mounted so that Time Machine can do its automatic backups.

Well I found a way to avoid having to manually mount and unmount (eject) my drive by using shell scripts and LaunchAgents to achieve the task. The added benefit is that I have control over the timing of the frequency of the Time Machine backups too!

Note: This works on OS X Lion or later. There is one caveat, in that when attempting to restore files from your Time Machine drive, you will need to disable the launch agents, as well you should re-activate Time Machine in the system preferences so that the system recognizes the drive for restore purposes.

Step 1

Create a plain text file named timemachine_mounter.sh with the following contents:

#!/bin/bash
# Set the drive name that we mount for our backups 
vol_mount="Time Machine"
# Conditional argument: if mounted entry has the volume name in the variable string
if ! mount | grep "$vol_mount" ; then
	# Drive isn't mounted, so: mount. A LaunchAgent will pick this OnMount action up and run the backup script
	diskutil mount "$vol_mount"
else
	# Drive is mounted, so: run the backup script
	timemachine_backup.sh
fi

Save the file in the /usr/local/bin/ directory at the base of your system drive. You may need to first save the file to your desktop then use finder to move it to that directory, it will ask to authenticate. Or use sudo in Terminal to move the file there instead, and make sure that ownership belongs to you (the user that logs in), in my case the assigned user:group was mike:staff.

Step 2

Create a plain text file named timemachine_backup.sh with the following contents:

#!/bin/bash
# Set the drive name that we mount for our backups 
vol_mount="Time Machine"
# Conditional argument: if mounted entry has the volume name in the variable string
if mount | grep "$vol_mount" ; then
	# Drive is mounted, so: backup and then eject after
	tmutil startbackup -b && 
	diskutil unmount "$vol_mount"
fi

Save the file in the /usr/local/bin/ directory again with the same ownership credentials as the previous script.

Step 3

Create a plain text file named com.apple.TimeMachine_OnLoadSchedule.plist with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.apple.TimeMachine_OnLoadSchedule</string>
	<key>RunAtLoad</key>
	<true/>
	<key>StartInterval</key>
	<integer>7200</integer>
	<key>Program</key>
	<string>/usr/local/bin/timemachine_mounter.sh</string>
</dict>
</plist>

Save the file in the ~/Library/LaunchAgents/ directory inside your User folder/directory (~/).

What the above file does is register in the system to run the mounter script:

  • when I first log in
  • consecutively every 2 hours

Step 4

Create a plain text file named com.apple.TimeMachine_OnMount.plist with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.apple.TimeMachine_OnMount</string>
	<key>StartOnMount</key>
	<true/>
	<key>Program</key>
	<string>/usr/local/bin/timemachine_backup.sh</string>
</dict>
</plist>

Save the file in the ~/Library/LaunchAgents/ directory as well.

What the above file does is register the system to run the Time Machine backup script whenever the drive gets mounted. This can happen when:

  • I physically connect the drive
  • the scheduler LaunchAgent above, runs the driver mounter script

In Terminal, make sure the shell scripts are executable, unload the default plist (if you didn’t turn off your Time Machine automatic backups in the System Preferences) and finally load the new LaunchAgent in your local LaunchAgent startup folder:

chmod +x /usr/local/bin/timemachine_*.sh
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.backupd-auto.plist
launchctl load ~/Library/LaunchAgents/com.apple.TimeMachine_OnMount.plist
launchctl load ~/Library/LaunchAgents/com.apple.TimeMachine_OnLoadSchedule.plist

Lastly…

You can change the com.apple.TimeMachine_OnLoadSchedule.plist’s integer value for the starting interval 7200 integer to something more reasonable (e.g., 3600 seconds is one hour,… multiply at will.) I have my backups run every two hours.

The good thing about using a LaunchAgent is that:

  • if your computer goes to sleep or is shut off, the backup will begin at the next time you log in and reset the countdown from that point onward
  • if Time Machine is already running it won’t try to run the process until the next projected sync time
  • if the drive is freshly connected or mounted already, Time Machine will begin backing up your changes and eject after its done

Font rendering issues on Google Chrome on OS X

There seems to be a small problem with many websites viewed in the latest version of Chrome on OS X as of recently (version 22.0.1229.79 on September 27, 2012).

There seems to be a small problem with many websites viewed in the latest version of Chrome on OS X as of recently (version 22.0.1229.79, updated on September 26, 2012).

The issue, documented here on the chromium issues tracker, talks about the fonts looking slightly more bold, or heavier, thicker and sometimes fuzzy due to a small repair job done on CSS -webkit-font-smoothing property that many web designers and developers were using to make their custom web-font typefaces render as intended by the glyph outlines in the fonts that they embedded on their websites.

bungeman@chromium.org reports that the bug where it also affected the weight of the text as a side effect has been fixed.

He also mentions that the additional weight of the typeface is rendered on purpose by the CoreGraphics API on OS X. There is a setting on the system that smooths text for LCD monitors, dialating the glyph outline by a factor of two, and that there was in fact a bug with the previous -webkit-font-smoothing: antialiased CSS property that ignored the CoreGraphics doubling of the dilation effect and rendered the font to its intended outlines without any smoothing.

Now that the bug has been fixed in Chrome’s code, the antialiasing bug is no longer dismissing the CoreGraphics LCD smoothing and therefor the fonts look heavier.

There isn’t a straightforward solution to fix the bolding of type on webkit browsers on OS X, however one might try addressing Apple OS X’s CoreGraphics LCD font smoothing directly by turning off your system’s LCD smoothing in System Preferences (under Appearance or General Settings), or with the following command in Terminal and restarting your browser.

defaults -currentHost write -globalDomain AppleFontSmoothing -int 0

The default when using lcd smoothed text is 2. To reset to the default value, use this command:

defaults -currentHost write -globalDomain AppleFontSmoothing -int 2

Note: This won’t modify the way your website is viewed on other people’s computers with OS X and webkit-based browsers. This only affects your ownlocal OS X system LCD font smoothing rendering.

Update: apparently the Chrome team is going to revert the fix to a planned bug so that they can buy themselves time to release a proper solution.