Stupid Mac::Glue Tricks: UI Scripting

pudge on 2004-05-17T04:42:14

You can use Apple's UI scripting with Mac::Glue.

Experienced users might notice that you need to set the target app to be frontmost, and the method used here is to use Mac::Glue, which you can't do with non-scriptable apps. This should be coming in a future version of Mac::Glue, but until then, you can use various other methods to set the frontmost app. And of course, this is still quite useful for many scriptable apps, since many scriptable apps don't have full scripting support.

#!/usr/bin/perl use Mac::Glue;

my $app = new Mac::Glue 'System Events'; my $safari = new Mac::Glue 'Safari'; $safari->activate;

$app->obj( menu_item => 'Close Tab', menu => 'File', menu_bar_item => 'File', menu_bar => 1, process => 'Safari' )->click;


Also, you really should have the UI Element Inspector for this. I think it is included with Panther's dev tools, but I am not sure. Regardless, this is the important portion of its output, to create the above script: