Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pudge (1)

pudge
  (email not shown publicly)
http://pudge.net/
AOL IM: Crimethnk (Add Buddy, Send Message)

I run this joint, see?

Journal of pudge (1)

Sunday May 16, 2004
11:42 PM

Stupid Mac::Glue Tricks: UI Scripting

[ #18784 ]

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:

<AXApplication: "Safari">
  <AXMenuBar: "">
  <AXMenuBarItem: "File">
   <AXMenu: "File">
    <AXMenuItem: "Close Tab">

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.