2

My first Problem: For some reason the Applescript Editor is not able to pick up events when recording from Keynote'09 (I already turned on the acessibility options). The Editor stays blank for all actions I perform. It works perfectly for things like Finder though.

The resulting problem: I still want to tell Keynote to export presentations so I made this Script:

set thisFile to "/Users/ks/Desktop/test.key"
tell application "System Events"
    tell application "Keynote"
        activate
        open thisFile
        set frontmost to true
        click menu item "Export…" of menu 1 of menu bar item "File" of menu bar 1
    end tell
end tell

This script will choke on the last line (the one with "click menu item") when being saved saying: "expected end of line but found class name" and "menu item" will be highlighted. I don't know how to fix that. Any suggestions? I see code all over the web doing the exact same thing. Is this a version Issue because its Keynote '09?

3
  • So apparently these actions are not defined, so I need to use tell application "System Events" tell process "Keynote" But then, the submenu items are still not found.
    – eddeeye
    May 7, 2011 at 20:22
  • try using automator.
    – user6124
    May 8, 2011 at 1:36
  • Automator doesn't have any export actions and the Watch me do action attaches to the names of the presentations, which makes it impossible to use for batch processing.
    – eddeeye
    May 8, 2011 at 19:43

2 Answers 2

3

The following works for me:

set thisFile to "/Users/danielbeck/Downloads/test.key"
tell application "System Events"
    tell application "Keynote"
        activate
        open thisFile
    end tell
    tell process "Keynote"
        click menu item "Export…" of menu of menu bar item "File" of menu bar 1
    end tell
end tell

Changes:

  • activate makes the application frontmost, AFAICT.
  • GUI scripting requires the process of application "System Events", not the application of the same name.
  • You need to enter the actual ellipsis character … (Opt-; on International layout) instead of the HTML entity.
1

The correct form of address is

menu item "Export…" of menu "File" of menu bar item "File" of menu bar 1 of application process "Keynote" of application "System Events"

See Finding Control and Menu Items for use in AppleScript User Interface Scripting over at MacOS Hints for a script that will quickly extract the proper addresses of any apps' UI elements for you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .