Site Overlay

Mac tip: synchronizing folders between Macs

Mac Folder Sync

Since MobileMe will sunset eventually (2012), I started to look for a replacement for iDisk. I used to use it as my Home directory (except for sensitive information, since there’s no encryption) because I could have the same documents in all of my Macs, plus access them from any iOS device.

Now that the party has a date to end, I needed an alternative. For non-sensitive documents (public technical documents, public domain sheet music and guitar tabs), I’m using Dropbox. I can access it from GoodReader on the iPad/iPhone and keep it synchronized across all my Macs as well, so it fits for PDFs I need on the road. For OmniFocus, I’m using their new OmniSync beta service. That leaves only other documents in the open.

For sensitive/confidential information, or information I don’t want people peeking at, I’m using an Automator script. I have it in my notebooks, and when I’m at the office, they automatically sync with my iMac workstation. It’s very neat and simple to do. Just launch Automator and start dragging the actions you need to the right blank frame. Basically, you need to do the following:

  1. Add ‘Get Specified Finder Items’ and select your source folder.
  2. Add ‘Set Value Of A Variable’ and create a new variable (drop down box) called ‘source_folder’.
  3. Add ‘Get Specified Finder Items’ and select your target folder. Right click on this newly created action and select ‘Ignore input’. This step is VERY important! If this is done correctly, you will see no connector between this box and the previous one.
  4. Add ‘Set Value Of A Variable’ and create a new variable (drop down box) called ‘target_folder’.
  5. Add ‘Get Value Of A Variable’ and select ’source_folder’. Right click on this newly created action and select ‘Ignore input’.
  6. Add ‘Get Value Of A Variable’ and select ’target_folder’.
  7. Add ‘Run Shell Script’. Select ‘Pass input as arguments’ (drop down box) and add the following command in the textbox: rsync -va —delete “$1/” “$2/”

    This will do the actual synchronization. The ‘-v’ switch stands for verbose (in case you want to log the command output — we’ll see that in a minute), ‘-a’ stands for archive, which means the operation will be recursive to the subfolders within that folder (it will preserve file permissions as well) and ‘—delete’ will delete any files in the target folder ($2)that were deleted in the source folder ($1).

  8. The operation of synchronizing itself is done in the last item. Now you may optionally:• Log the rsync operation, to make sure it went okay. You’ll do that by adding ‘New TextEdit document’. This will create a new TextEdit window containing the output for the command.
    • Create a Growl notification to tell you the operation is done by adding ‘Show Growl Notification’ and creating a custom message.

Now save it in your scripts folder (~/Library/Scripts). If you don’t have the Script Menu in the menu bar, launch Apple Script Editor, open its Preferences and mark the ‘Show Script menu in menu bar’ checkbox. You’ll then be able to see your script in the Script Menu and launch it from there. If you want that to run automatically, then you can explore the Automator options to run that periodically.

Happy scripting!

Related stories: Apple, Mac, OS X, Technology

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.