1

In answering this question I wrote this script:

global presenterNotes 
tell application "Keynote"
    activate
    open (choose file)
    tell front document
        set presenterNotes to presenter notes of every slide as text
            set the clipboard to presenterNotes
        do shell script "pbpaste > ~/keynote-notes.txt"
    end tell    
    quit application "Keynote" end tell

My question is: in the instance above when I replace the "shell script" statement with the statement below why does this statement work:

tell application "TextEdit"
        activate
        make new document
        set text of front document to presenterNotes
        quit application "TextEdit"
    end tell

Example 1: but this one does not:

tell application "TextEdit"
        activate
        make new document with data presenterNotes as text

Example 2: nor does:

make new document with presenterNotes

I know there are other ways to make it work like copy to clipboard and then issue a command+c.

I would like to understand why the global variable is not being transferred to the textEdit document, in particular in Example 1 above, as applescript does not throw an error.

1

There is a hidden error that is generated when you run your "working" script... You have to bump the shell script part of the code into its own tell current application block as shown in the second example below...

This version works for me with creating a TextEdit document:

global presenterNotes
tell application "Keynote"
    activate
    -- open (choose file)
    tell front document
        set presenterNotes to presenter notes of every slide as text
        set the clipboard to presenterNotes
    end tell
    tell application "TextEdit"
        activate
        make new document with properties {name:"KeynoteNotes.txt"}
        set text of front document to presenterNotes
    end tell
end tell

The shell pbpaste version with proper blocking to avoid error -10004:

global presenterNotes
tell application "Keynote"
    activate
    -- open (choose file)
    tell front document
        set presenterNotes to presenter notes of every slide as text
        set the clipboard to presenterNotes
    end tell
    tell current application
        do shell script "pbpaste > ~/keynote-notes1.txt"
    end tell
end tell
  • Thanks for answering but I still don't know why Example 1 and 2 don't work with the global variable, if you can answer that I will definitely mark your answer correct. – Deesbek Aug 21 '14 at 21:50
  • Can you post the full script for your examples and not just the couple line excerpts? Mine is only slightly different by the way the tell and end tell are placed. – beroe Aug 21 '14 at 23:58

You must log in to answer this question.

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