I finally decided to play around the the Automator application that is part of Mac OS X. I am a big fan of workflow based technologies so I was excited to see what it has to offer.
My goal was to create a Finder Automator plug-in that would display any subversion project that I had modified and needed to be committed back to the repository. To make things even more interesting I decided to use a number of different tasks just to see how they all interact through Automator.
I fired up Automator and got to work.
1. I dragged the "Get Selected Items" action onto the workflow designer window. This is the action that would receive the list of folders I selected from any Finder window.
2. I dragged in the "Get Folder Contents" action. This action would return the list of items (folders) under the subversion repository folder that was selected in step 1.
3. Because Automator does not contain subversion actions (there are CVS ones) I had to go it on my own. I dragged in a "Run Shell Script" action and after much work and syntax frustrations and two other people helping me I ended up with a very small and simple script.
for fn in "$@"
do
svn status $fn | grep ^M >nul
if [ "$?" = "0" ]; then
p=`echo $fn | awk 'BEGIN{FS="/"} {print $NF}'`
echo "$p has been modified"
fi
done
Automator will pass in the list of items found in step 2. So I created a simple for loop to cycle through them all. For each item I run the subversion status command, pipe it to grep looking for a modified flag. grep will return a code identifying whether or not it found any matches. If the project has any modified files I use awk to strip out just the file name from the full path and turned it into a more readable message.
4a. Now that we have a list of modified projects from step 3 we need to provide feedback on the modified projects. This is where I had some fun by dragging in the "Speak Text" action. Now when the automator workflow is run it will speak what subversion projects have been modified. Lot's of fun but eventually does get a little old.
4b. To make things a little more bearable and less annoying to my co-workers I decided to modify the workflow to display a pop-up window with the modified projects listed. This is where I was really surprised to find out that Automator does not have any default action for displaying a message. Therefore I decided to try some AppleScript and dragged in an "AppleScript" action and added the following code.
on run {input, parameters}
if input is not {} then
if the class of the input is list then
set s to ""
repeat with i from 1 to length of input
set s to s & item i of input & "
"
end repeat
display dialog s
else
display dialog "No SVN Projects Have been modified"
end if
else
display dialog "No SVN Projects Have Been Modified." buttons {"OK"}
end if
return input
end run
The above AppleScript is simply converting the list that is passed in to a large string because the 'display dialog' will not handle the list. There are some quirks with the display dialog; not being able to set the title bar text (there might be a way I but didn't quickly find it); and the window size not growing when there is a lot of text.
5. Finally I saved the Automator workflow as a Finder plug-in which made it accessible off of the finder pop-up menu.
Conclusion:
Automator is a fun tool and has some interesting possibilities. However, its lack of branching actions will limit its use to simple sequential data processing chores.