Sunday, July 27, 2008

Quick AppleScript Attack on SVN Diff

I'm doing some PHP to drive some Flash gauges. But I've really not a lot to say about that. Instead something about another quick SVN Diff hack.

Whilst my Automator right-click context menu hack worked, the sizeable delay (if 10 seconds is sizeable) was annoying me.

Now, I know third-party tools might solve this problem more easily, I've sort of got a 'do it with things lying about on my machine' bug. However, I also don't want to spend more than 30 minutes development, which sort of discounts Obj-C, C++, C, Java, even Python, Perl, etc. (Yeah, of course you could do it in 15 minutes with these.)

So, it sounded like another approach was in order. How about a droplet - an application were you can just drop the files on to? A quick search on the great place of quick hacks - Mac OS X Hints - revealed several things that were very close and could be changed quickly. AppleScript, of course.

Anyhow, I've uploaded a text file with the AppleScript code to morestuff on Lightsoft. Load it into the Script Editor and save it as an Application. Again it relies upon being installed. So get that off morestuff (it's inside and install it as per the instructions (you don't need the Automator stuff).

Some notes:

(All time measurements are on my machine only)
  1. Launching takes about 4-5 seconds before FileMerge shows the file - although 1-2 seconds are FileMerge launching and displaying the file.
  2. When you save the application, you probably don't want "Startup Screen" as this gives a large dialogue before anything happens.
  3. If you save as "stay open" then you can drop more files onto the already launched script - this means end to end is 1-2 seconds (even with a FileMerge launch)!
  4. Keep it in the dock for ease of use and drop right onto it.
  5. For reasons I haven't figured out yet, you can't use the script again until you quit FileMerge. This is not the case if you get Terminal to run the script (see the commented out code in "perform_SVN_diff"). This also happened in the Automator version.
  6. It also supports just running the script - you get a file selection dialogue.
Have fun!

Sunday, July 20, 2008

Micromouse Maze Viewer and Lessons Learnt

I've created a prototype for a Micromouse maze file viewer/editor. I've uploaded it with some details to the Lightsoft 'more stuff' page.

Two comments about writing the actual utility:

1. It's a fairly small program - and the basics only took me a couple of evenings. But it still took a couple of weeks of evenings before it was in a fit state to release to other people including tiny features which I thought were pretty essential plus some basic clean-up ('polish'). Even with this work it's still got some rough edges and yucky bits in places.

It sort of goes to show that the effort to do a general release of any program is not tiny.

2. I've now got a to-do list of clean up items and new features longer than the original specification! At first glance this appears rather strange but it shows how a relatively simple project can 'grow arms and legs' and take on 'a life of it's own'.

Of course I still want feedback. Without feedback you can't really know what's good and bad and what needs changing.

Still, since this started as a side project, I think I'll leave any changes for a few weeks and get on with the main robot code and LWC web gauge integration.

Saturday, July 19, 2008

SVN diffs from the Mac finder


As I recently blogged, I've installing SCPlugin to get Finder integration of a (limited) set of Subversion operations from the Finder contextual menu. However, this set of operations does not include the subversion diff. I've therefore been looking for an additional solution since I really like SCPlugin as a client otherwise and have considered various methods and third-party tools.

The solution I've come up with uses just standard MacOSX stuff: FileMerge that comes with the Apple Developer Tools (and it's command line helper 'opendiff') and Automator that originally shipped with MacOSX 10.4 Tiger (although I'm using MacOSX 10.5 Leopard and I don't know if this will work exactly the same on 10.4).

Using this solution you right-click (control-click) on one or more files and select More->Automator->svn-diff and it shows you the differences between the current and baseline in Apple's FileMerge. Just what I wanted.

The chain of events that do the work are:
  1. Automator step 1 gets the selected finder items
  2. Automator step 2 runs a Shell Script, using /usr/bin/python (since I know more Python than standard shell script). The inputs are passed as arguments. The script is shown below.
  3. This Python script runs the Subversion command line (svn) and asks it do a diff using a separate diffing command.
  4. The diff command passed is a script called ''. This is a minor modification of the script '' which I downloaded from the Subversion site 's tools contribution page along with a cool conflict resolution script that uses FileMerge as well. The minor modification takes out the check for Apple's terminal. I store all these shell script files in /usr/local/bin (which is referenced in the Python script - so it needs to be there otherwise the script won't work).
  5. This calls 'opendiff' which is a command line tool which sends the files to FileMerge.
  6. FileMerge launches and shows you the files.

Not exactly the shortest chain of events in the history of viewing a file! It is possible we could skip steps 3 and 4 totally, since we are differencing always between the baseline and current - the base text file is stored in the '.svn' directory. However, this information is private and may have/could change on different versions of Subversion. Additionally the script '' sorts out a lot of unusual conditions like temporary files. Step 5 is another one that seems to add no direct value - but does make the whole process simpler avoiding us figuring out about running processes, apple events and the like. So I think - unless I get major delays or problems, I'll leave it like this for the moment.

The Python script executed by the Automator looks like this:
import sys
import os
for f in sys.argv[1:]:
command = 'svn diff "'+f+'" --diff-cmd /usr/local/bin/'
print command
print "Completed"

The two print statements are simply for debugging purposes in Automator.

It's slightly slow - on my machine it takes about 3 seconds for the command line version to load into FileMerge (including FileMerge to updating the screen to show differences) and about 10 seconds using the Automator menu. Most of that time appears to be the Automator loading and set-up. However, you can select multiple files across multiple directories (opened with the disclosure triangle) and they load a couple of seconds after each other. There is a possibilities of shortening the delays in the shell script as well. Something for another day.

You can find copies of all the scripts mentioned here along with installation instructions on the Lightsoft web site in the 'more stuff' section.

Wednesday, July 16, 2008

New Subversion 1.5

So as if converting 50 million archives to Subversion elsewhere wasn't bad enough (and you really have no idea how much work and stress that's caused) I wanted to get a GUI client working over here.

Suddenly, a couple of days ago, I realised that using the command line - which I've been using for ages and generally is very intuitive for a command line tool - was slowing me and my use of Subversion down. I don't mean it was taking a long time, just that, sometimes, a quick glance is so much better.

So SCPlug-in, which is meant to be like Tortoise for MacOSX. Available in SVN v1.46 and 1.50. Hmmm.... I have v1.44. Prefer to have the same version across the board. So ... upgrade command line tools to 1.46? Except ... no available build that doesn't need a port library. So let's go v1.50. Hmmm. Doesn't work. Installed into a different ... later ... path.

The short end to the story was that some manual install of v1.50 out of the package into the original v1.44 directory was the simplest option. (Note to self: remember to register shareware). SCPlug-in required a bit of fiddling to get icons consistent (Off mailing list: restart finder with no windows open, right-click on desktop, refresh-icons), but it seems to be pretty cool. Could do with diff operation. No, could REALLY do with a diff option. Using FileMerge would be great.
Newer›  ‹Older