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