Slash Boxes
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)

  (email not shown publicly)
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.

use Mac::Glue;
my $app = new Mac::Glue 'System Events';
my $safari = new Mac::Glue 'Safari';
    menu_item       => 'Close Tab',
    menu            => 'File',
    menu_bar_item   => 'File',
    menu_bar        => 1,
    process         => 'Safari'

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.
More | Login | Reply
Loading... please wait.