Posted by Kevin D Smith @ 10:39 pm on July 6th 2007

FileMerge and CVS

I’ve been working on improving my workflow in programming lately. This is mainly due to the fact that I now work from home. Working from home poses some new problems since I don’t have a 1Gb connection to my network resources anymore. In the process of rethinking my processes, I decided to play around with FileMerge, one of Apple’s developer tools. FileMerge enables you to visually see the difference between two files and interactively merge them into one final form. This is a very common operation when using CVS and you have a conflict with a push from another developer, or you just want to see the differences between two file revisions. Because I use it in conjunction with CVS so much, I thought I’d add some CVS features to FileMerge.

The result of this work is cvs-opendiff. It’s called cvs-opendiff because Apple supplies a utility called opendiff which invokes FileMerge from the command-line, and cvs-opendiff invokes this command along with various CVS commands to do its work. The feature list for cvs-opendiff is shown below.

  • Compares two files like diff
  • Compares the current working file with the current revision in CVS
  • Compares two file revisions or dates
  • Continues running until FileMerge is exited, or the window containing the file comparison is closed

This last feature is the key feature since the opendiff command exits as soon as it finished invoking FileMerge. This behavior is often undesirable when merging files especially when the merge is invoked by a third tool that expects this behavior.

I’d love to hear your comments and suggestions for cvs-opendiff. I’m planning on starting to work with subversion soon, so I imagine I’ll be updating it to work with that eventually.

Posted by Kevin D Smith @ 9:56 am on September 9th 2006

Adding Custom Applescript Commands to an Applescript Studio Application

While it’s always possible to script an Applescript Studio Application using GUI scripting, it’s pretty clunky to constantly be referring to windows and buttons. The good news is that it’s not too difficult to add custom commands to your application. However, you will need to know some Objective-C to do this.

(more…)

Posted by Kevin D Smith @ 5:54 am on September 5th 2006

Starting the Main Feature in Apple’s DVD Player

I was looking for a way to start a DVD (or DVD folder) in Apple’s DVD Player using Applescript such that it skips the menu, trailers, etc. It turns out that this is fairly simple for most disks because most DVDs start the main feature at chapter 1 of title 1. Here is the code.

tell application "DVD Player"
    play dvd
    set title to 1
    set chapter to 1
end tell

For discs that don’t fit this model, you can store away the proper title and chapter numbers and look them up on a per DVD basis.

Update: I’ve found out that this does not work with all discs. However, I was using this trick with DVDs ripped by MacTheRipper with the DVD navigation limitations removed.

Posted by Kevin D Smith @ 5:36 am on September 5th 2006

Drag and Drop Tracks from iTunes in Applescript

I was working on a project in Applescript Studio recently that required tracks from iTunes to be dragged into an image view. It appears as though this isn’t possible to do in plain Applescript, but I did find a way to do it with a combination of Applescript, Objective-C, and the call method command.

Add the files AppHelper.h and AppHelper.m, as shown below, to your Applescript Studio project.

// AppHelper.h
#import 
#import 
@interface NSApplication (AppHelper)
- (NSArray *)tracksFromPasteboard:(NSPasteboard *)pboard;
@end
// AppHelper.m
#import "AppHelper.h"
@implementation NSApplication (AppHelper)
- (NSArray *)tracksFromPasteboard:(NSPasteboard *)pboard
{
    // Get iTunes track information from the pasteboard as a property list,
    // get "Tracks" key from property list dictionary, then return all of
    // the values of the "Tracks" dictionary.
    return [[[[pboard propertyListForType:@"CorePasteboardFlavorType 0x6974756E"]
                       objectForKey:@"Tracks"] allValues] retain];
}
@end

Now in your Applescript code, you can call the tracksFromPasteboard: method using the call method command in Applescript. You will get a list of all of the dragged tracks. Each item of the list is a record with keys such as |Name|, |Location|, |Artist|, etc. As far as I can tell, there is no way to drag a playlist and get playlist information.

on drop theObject drag info dragInfo
    -- Get a list of the data types on the pasteboard
    set dataTypes to types of pasteboard of dragInfo
    -- Get the iTunes track list data from Objective-C method
    if "CorePasteboardFlavorType 0x6974756E" is in dataTypes then
        set tracks to call method "tracksFromPasteboard:"
                           with parameter (pasteboard of dragInfo)
        display dialog |Location| of item 1 of tracks
    end if
end drop