Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
    
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 '11 at 20:22
    
try using automator. –  user6124 May 8 '11 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 '11 at 19:43

2 Answers 2

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.
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.