Compare Files Line-by-Line (or Image-to-Image)

Two of my favorite tools for line-by-line text comparison are diff and FileMerge. One reason why I like them so much is because they are lightweight alternatives for word processors like Microsoft Word, which you wouldn’t be inclined to open for coding (that’s one of my primary uses).

diff is a simple CLI-based tool accessible on most *nix systems. The basic format is diff <options> <file1> <file2>. It comes with a lot of powerful options too. To list a few:

  • Ignore tab expansion, blank lines, and other white space
  • Ignore case
  • Ignore matching lines
  • Side-by-side output
  • Compare files in directories
  • Recurse through subdirectories
  • Reporting identical files or simply whether or not differences exist

FileMerge is as simple as it gets for file comparison with a GUI. FileMerge comes with any installation of Xcode so it’s basically free. However, you’ll have to download the whole Xcode package (~1 GB) to get it unless you can find it floating around on the net alone.

FileMerge Screenshot

FileMerge allows you to select the changes you want to keep through a menu at the bottom-right that designates the favored document. By default, the right (as opposed to left) document is selected. Below the two separate documents is the final output that will result from the merge. FileMerge also allows you to edit/add content in this section before merging and saving.

As I was writing this post, I got a referral from Russ to a cross-platform comparison tool called Perforce. The cool thing about Perforce (besides being platform agnostic) is it compares not only files and folders, but images too. Not to mention it’s FREE. I only briefly read about it and watched some sample videos on the site, but it’s pretty powerful. It also can be used in parallel with Git. Read about it here.

After the recommendation to checkout Perforce, I started doing some more research and stumbled upon a couple other tools. First off, free code editor TextWrangler (Mac) includes file comparison. Diffmerge seems like a really cool alternative. It’s also free, available on multiple pllatforms and includes merging of 3 files and integration with Windows Explorer. Kaleidoscope is another option, though you’ll have to pay ~$40. It includes many of the same features as Perforce.

What do you use when you need to compare files? Have any recommendations?

Use Spotlight to do Math

Quick tip for today. If you own a Mac you can do arithmetic in Spotlight. No need to even open Calculator. Spotlight performs a variety of functions too, including:

  • Basics: addition, subtraction, multiplication, division
  • Powers & Squareroots
  • Sin, Cos, Tan and their inverses (sinh, cosh & tanh)
  • π (Pi)
  • e, ln & log

So next time you need to do some quick math, use Spotlight!

Spotlight Math

Lock Your Screen on Mac

The Windows shortcut for locking the screen is pretty convenient (Windows Key + L). When you’re at work or a more public setting it’s nice to be able to lock your screen quickly before leaving your computer temporarily. In my searches to find a convenient way on Mac, I found a number of ways, many of which involve extra applications and menus in the menubar. I’ll briefly mention a few ways that may interest you, then mention the method I settled on.

One way is to add the Keychain Access menu to your menubar. To do this, Open Keychain Access (Cmd + Spacebar >> type Keych >> Enter) then open preferences (Cmd + ,) and check the first option to “Show keychain status in menubar.” Now you can lock the screen from the Keychain Access menu.

Keychain Access Menu

Another way is to enable the Fast User Switching menu. Do this by accessing System Preferences >> Users & Groups >> Login Options and then checking the option to “Show fast user switching menu as…” This will add a menu next to Spotlight and the clock allowing you to show the login window.

Fast User Switching Menu

While both of these methods are effective, they involve extra clutter in your menubar. So I’ve discovered two other easy ways that involve shortcuts. The first method uses the Screensaver Shortcut. To make this work, you’ll have to change your security settings such that your computer requires a password immediately after the screensaver starts. This can be done by navigating to System Preferences >> Security & Privacy. Check the first box and set the menu to “immediately”. Now all you have to do is key Ctrl + Shift + Eject. If you’ve done it correctly, you should be asked for a password as soon as you exit the screensaver via moving the cursor or pressing a key.

I prefer to have my screensaver come on relatively quickly (10-15 minutes) and I don’t like it when my computer asks me for a password immediately, so I went another route using Automator. It turns out you can control Fast User Switching from the command line using a binary called CGSession. CGSession takes two options (that I know of), namely -suspend and -switchToUserID <value>. Simply open Automator (Cmd + Spacebar >> type Autom >> Enter) and under the Utilities section find “Run a shell script” and drag it to the section on the right. Now copy and past the following script in the field where it says “cat” by default:

/System/Library/CoreServices/Menu\ Extras/ -suspend

Automator Screenshot

Be sure to change the menu for “Service receives” to “no input”. Now save this simple one step workflow as a service and call it something like “Lock Screen”. Now we are going to assign this service a global hotkey/shortcut. Navigate to System Preferences >> Keyboard >> Keyboard Shortcuts >> Services. At the very bottom, you should see a general service called “Lock Screen”. Make sure the box is checked and when you hover over it you should see a little button that says “Add Shortcut”. Click that and add a shorcut like Cmd + Alt/Opt + L. Now you should be able to lock your screen globally at any time.

System Preferences Keyboard Shortcuts

Alternatively, you could try using Quicksilver–a simple app that allows you to create powerful global shortcuts and the like. I used this before creating a service through Automator; however, I found it a bit cumbersome to use and setup. You shouldn’t need an extra app for something so simple.

Which way do you like best?

App of the Day: Paint for Mac = Paintbrush

The other day I was looking for a Mac alternative to Windows’ Paint. Thus I discovered Paintbrush. It’s basically a clone of Paint and is great for simple tasks you don’t need Photoshop for (or maybe you don’t own Photoshop). Plus Paintbrush is really lightweight (as you can imagine) so you don’t have to wait for Photoshop to load up. I used Paintbrush to create the mini-icon for my website you see in the tabbed window of your browser.

Paintbursh Screenshot

Mac OS X User Defaults

Defaults is a tool that allows Mac users to acces the user defaults system. It’s the tool used in my last two posts that allows you to make changes like hiding your desktop icons or showing hidden/invisible files. Since then, I’ve found a more comprehensive list of useful defaults.

To keep things simple, I’m going to refer you to a whole list of useful defaults posted by Github user mathiasbynens which he refers to as the dotfiles. I suggest you briefly read through it. Some other default changes you might be interested in are:

  • Enable key repeat in Lion
  • Enable 2D Dock
  • Enable iTunes track notifications in the Dock
  • Show all filename extensions
  • Disable automatic shadow in screenshots
  • Disable press-and-hold for keys in favor of key repeat
  • Set a blazingly fast keyboard repeat rate
  • Remove the auto-hiding Dock delay
  • Empty Trash securely

For your convenience, I’ve included the list below.

# Turn key repeat on in Lion (as opposed to selecting special characters)
defaults write -g ApplePressAndHoldEnabled -bool false

# Enable full keyboard access for all controls (e.g. enable Tab in modal dialogs)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3

# Enable subpixel font rendering on non-Apple LCDs
defaults write NSGlobalDomain AppleFontSmoothing -int 2

# Enable the 2D Dock
defaults write no-glass -bool true

# Automatically hide and show the Dock
defaults write autohide -bool true

# Make Dock icons of hidden applications translucent
defaults write showhidden -bool true

# Enable iTunes track notifications in the Dock
defaults write itunes-notifications -bool true

# Disable menu bar transparency
defaults write NSGlobalDomain AppleEnableMenuBarTransparency -bool false

# Show remaining battery time; hide percentage
defaults write ShowPercent -string "NO"
defaults write ShowTime -string "YES"

# Always show scrollbars
defaults write NSGlobalDomain AppleShowScrollBars -string "Always"

# Allow quitting Finder via ⌘ + Q; doing so will also hide desktop icons
defaults write QuitMenuItem -bool true

# Disable window animations and Get Info animations in Finder
defaults write DisableAllAnimations -bool true

# Show all filename extensions in Finder
defaults write NSGlobalDomain AppleShowAllExtensions -bool true

# Show status bar in Finder
defaults write ShowStatusBar -bool true

# Expand save panel by default
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true

# Expand print panel by default
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true

# Disable the “Are you sure you want to open this application?” dialog
defaults write LSQuarantine -bool false

# Disable shadow in screenshots
defaults write disable-shadow -bool true

# Enable highlight hover effect for the grid view of a stack (Dock)
defaults write mouse-over-hilte-stack -bool true

# Enable spring loading for all Dock items
defaults write enable-spring-load-actions-on-all-items -bool true

# Show indicator lights for open applications in the Dock
defaults write show-process-indicators -bool true

# Don’t animate opening applications from the Dock
defaults write launchanim -bool false

# Remove the auto-hiding Dock delay
defaults write autohide-delay -float 0

# Display ASCII control characters using caret notation in standard text views
# Try e.g. `cd /tmp; unidecode "\x{0000}" > cc.txt; open -e cc.txt`
defaults write NSGlobalDomain NSTextShowsControlCharacters -bool true

# Disable press-and-hold for keys in favor of key repeat
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false

# Set a blazingly fast keyboard repeat rate
defaults write NSGlobalDomain KeyRepeat -int 0

# Disable auto-correct
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false

# Disable opening and closing window animations
defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false

# Enable AirDrop over Ethernet and on unsupported Macs running Lion
defaults write BrowseAllInterfaces -bool true

# Disable disk image verification
defaults write skip-verify -bool true
defaults write skip-verify-locked -bool true
defaults write skip-verify-remote -bool true

# Automatically open a new Finder window when a volume is mounted
defaults write auto-open-ro-root -bool true
defaults write auto-open-rw-root -bool true
defaults write OpenWindowForNewRemovableDisk -bool true

# Display full POSIX path as Finder window title
defaults write _FXShowPosixPathInTitle -bool true

# Increase window resize speed for Cocoa applications
defaults write NSGlobalDomain NSWindowResizeTime -float 0.001

# Avoid creating .DS_Store files on network volumes
defaults write DSDontWriteNetworkStores -bool true

# Disable the warning when changing a file extension
defaults write FXEnableExtensionChangeWarning -bool false

# Show item info below desktop icons
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/

# Enable snap-to-grid for desktop icons
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/

# Disable the warning before emptying the Trash
defaults write WarnOnEmptyTrash -bool false

# Empty Trash securely by default
defaults write EmptyTrashSecurely -bool true

# Require password immediately after sleep or screen saver begins
defaults write askForPassword -int 1
defaults write askForPasswordDelay -int 0

# Enable tap to click (Trackpad)
defaults write Clicking -bool true

# Map bottom right Trackpad corner to right-click
defaults write TrackpadCornerSecondaryClick -int 2
defaults write TrackpadRightClick -bool true

# Disable Safari’s thumbnail cache for History and Top Sites
defaults write DebugSnapshotsUpdatePolicy -int 2

# Enable Safari’s debug menu
defaults write IncludeInternalDebugMenu -bool true

# Make Safari’s search banners default to Contains instead of Starts With
defaults write FindOnPageMatchesWordStartsOnly -bool false

# Remove useless icons from Safari’s bookmarks bar
defaults write ProxiesInBookmarksBar "()"

# Add a context menu item for showing the Web Inspector in web views
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true

# Enable the debug menu in Address Book
defaults write ABShowDebugMenu -bool true

# Enable the debug menu in iCal
defaults write IncludeDebugMenu -bool true

# Only use UTF-8 in
defaults write StringEncodings -array 4

# Disable the Ping sidebar in iTunes
defaults write disablePingSidebar -bool true

# Disable all the other Ping stuff in iTunes
defaults write disablePing -bool true

# Make ⌘ + F focus the search input in iTunes
defaults write NSUserKeyEquivalents -dict-add "Target Search Field" "@F"

# Disable send and reply animations in
defaults write DisableReplyAnimations -bool true
defaults write DisableSendAnimations -bool true

# Copy email addresses as `` instead of `Foo Bar ` in
defaults write AddressesIncludeNameOnPasteboard -bool false

# Disable Resume system-wide
defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false

# Disable the “reopen windows when logging back in” option
# This works, although the checkbox will still appear to be checked.
defaults write TALLogoutSavesState -bool false
defaults write LoginwindowLaunchesRelaunchApps -bool false

# Enable Dashboard dev mode (allows keeping widgets on the desktop)
defaults write devmode -bool true

# Reset Launchpad
[ -e ~/Library/Application\ Support/Dock/*.db ] && rm ~/Library/Application\ Support/Dock/*.db

# Show the ~/Library folder
chflags nohidden ~/Library

# Disable local Time Machine backups
hash tmutil &> /dev/null && sudo tmutil disablelocal

# Remove Dropbox’s green checkmark icons in Finder
[ -e "$file" ] && mv -f "$file" "$file.bak"
unset file

# Fix for the ancient UTF-8 bug in QuickLook (
# Commented out, as this is known to cause problems when saving files in Adobe Illustrator CS5 :(
#echo "0x08000100:0" > ~/.CFUserTextEncoding

# Kill affected applications
for app in Safari Finder Dock Mail SystemUIServer; do killall "$app" >/dev/null 2>&1; done

Which ones did you find most useful? Have any to add to the list?

Show/Hide Invisible Files on Mac & Other Secrets

Showing hidden files can be somewhat of a pain in Mac OS X. I’ve come up with a number of ways to make it easier for myself.

The simplest, most direct way of doing this is a command in the Terminal. One way is to navigate to the appropriate directory in Terminal and type ls -lha. Alternatively, you can type ls -lha <path/to/directory>. This will give you a list of all the hidden files for that directory. But maybe you aren’t proficient with Terminal commands and/or you need to do some file manipulation and/or you don’t want to use the CLI.

Much like my post Hide Desktop Icons on Mac, I’ve created a little script I call hidden that automatically shows and hides hidden files.


# checks file visibility and stores value in a variable
isVisible="$(defaults read AppleShowAllFiles)"

# toggle file visibility based on variable
if [ "$isVisible" = 1 ]; then
	defaults write AppleShowAllFiles -bool false
	defaults write AppleShowAllFiles -bool true

# force changes by restarting Finder
killall Finder

Paste that code into a text editor, save it to a directory in your $PATH and make it executable (chmod 755 <filename>).

HideSwitch ScreenshotTwo other alternatives I’ve stumbled upon are HideSwitch and Secrets Prefpane (at the time of this post the site was down. Get it at MacUpdate instead.) HideSwitch is just a simple mini-app with two buttons to hide and show hidden files. Secrets Prefpane is a just that: a button that shows up as a system preference and turns into a prefpane once clicked. However Secrets is quite powerful and can do a lot more than just show and hide files. Secrets includes a variety of features, such as:

  • Selecting the format and destination folder of saved screenshots
  • Changing the login window desktop picture
  • Changing Dock effects
  • Seeing the contents of folders when QuickLooking (I don’t think this works on Lion)
  • Enabling the debug menu in iCal

Those are just a few that I’ve found useful and interesting. Since it’s free, you may want to download it and check it out. Might have a feature you’ve been dying to have. Secrets also taps into many of the preferences of your other programs such as Adium, iTunes, Cyberduck, Skype, Preview, Transmission, etc.

Secrets Prefpane Screenshot

Hide Desktop Icons on Mac

Ever wanted to hide your desktop icons briefly and easily on Mac OS X for a presentation, screencast or just to hide everyday clutter? Here’s a simple Bash script you can use.


# checks visibility and stores value in a variable
isVisible="$(defaults read CreateDesktop)"

# toggle desktop icon visibility based on variable
if [ "$isVisible" = 1 ]; then
	defaults write CreateDesktop -bool false
	defaults write CreateDesktop -bool true

# force changes by restarting Finder
killall Finder

Paste that into a text editor and save it without a suffix/filetype as something like desktop. Then execute the following command while in the folder where you saved the script (preferably in your personal bin directory): chmod 755 desktop. You should be good to go as long as the directory you saved it in is mapped to your $PATH (If you aren’t sure what that means, read the 4th and 5th paragraphs of Clock In, Clock Out).

You can find some simple apps to do this if you are repelled by the Terminal or love extra menubar buttons; just search Google. Some of them cost money (CamouFlage – $1.99), though I don’t know who would pay for something so simple. There are some other free alternatives.