Blog | tag: Automator
Back to: Geek Stuff
Monday, 14. december 2009.

Synchronize two folders on a Mac with Automator and Rsync

Power of Automator and Unix combined

I really miss some good Automator tutorials online. It's such a great and I guess underrated and underused tool. Here I'll show you how to combine it with rsync to easily synchronise two folders.

Here is the finished workflow from the tutorial so you can use it right away and see how it's done for yourself: RsyncTutorial.workflow.zip 152kb

And here it is for the patient ones, step by step...

You'll start by opening automator.app, you can find it in your Application folder it has a nice icon which reminds me of eve from Wall-E. Once you start it, it will ask you what kind of workflow you're going to make, we'll choose Workflow:

First action we're going to add is "Ask for Finder Items" (it's inside Files & Folders category, but best way to find actions is to use search), that action simply opens finder window where you can choose file(s) or folder(s).

And here we can write some custom text in "Prompt" field, you can specify which folder will it open as a starting point (Start at), and we'll specify that we want only folders and we do not want multiple selection option.

Next we'll add "Set Value of Variable" action which will get the folder that you chose and write it's name into a variable that we'll use later with Rsync.

Next, we'll repeat it, we need another pair of Ask for Finder Items and Set Value of Variable actions. First we add Ask for Finder Items:

But the important thing here, is to ctrl + click (right click) on the Ask for Finder Items text and choose "Ignore Input" option, if you do not do this the whole thing will not work. Then we'll add Set Value of Variable:

And we'll click on Variable drop down and choose New variable and name it for example "target_folder".

Next step is optional, we'll add confirmation window (Ask for Confirmation action) that will ask us if we chose the right folders and print out the names of the folders we're going to sync:

Here you start writing something like "You'll be syncing from" than you drag the variable "source_folder" from variable list below, continue by writing " to " and than drag "target_folder" variable from the list, and finish your confirmation text, for example " is that right?".
Here you're also have to say to automator that you want to ignore input from previous action.

Next we'll add two Get Value of Variable actions that will pick up the values of source and target variables:

Again, ignor the input from the Ask for Confirmation action.
After that, add Run Shell Script action which will tell rsync what to do:

You have to change "Pass input" to "as arguments" and than write rsync -va --delete "$1/" "$2/" $1 represents first variable that you're sending in, and $2 second one (first one being source_folder and second one target_folder). You can play with rsync options here and maybe exclude some files from syncing.

And here is another optional action, we'll add New TextEdit Document at the end. That will open new TextEdit window with output from Rsync, so you can see what Rsync actually did.

And that's it! Now we're going to save it, the best way I think is to save the workflow into your Scripts folder (you go to your home folder and there you'll find Scripts folder). I named mine workflow "RsyncTutorial". Then if you have Script Menu turned on in menu bar (If you don't you can enable it by running AppleScript Utility, located at /Applications/AppleScript/, and checking the "Show Script Menu in menu bar" checkbox) you'll see something like this when you click on the Script Menu:

And if you click on it your workflow will start by asking you for folder to sync from.

Comment

Fresh One

Photo

Nature, Up Close & Personal

  • 5.00
    • 1
    • 2
    • 3
    • 4
    • 5
(current rating: 5.00 | 1 votes)
Calendar

January 2010

  • mon
  • tue
  • wed
  • thu
  • fri
  • sat
  • sun
  •  
  •  
  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

December 2009

  • mon
  • tue
  • wed
  • thu
  • fri
  • sat
  • sun
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

May 2009

  • mon
  • tue
  • wed
  • thu
  • fri
  • sat
  • sun
  •  
  •  
  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31