2

I have a script which loads a Numbers document in order to retrieve a specific cell value to use in creating a reminder.

My code is below. I believe I'm using correct syntax to load the value into a variable, but I'm just getting a 0 in the reminder and the dialog doesn't show.

set transferValue to 0

tell application "Numbers"
    activate
    try
        open filePath
        tell sheet "Monthy Expected"
            tell table "Account Budget Share"
                set transferValue to value of cell "B4"
                display dialog value of cell "B4"
                display dialog transferValue
            end tell
        end tell
    on error

    end try
end tell

Is there something wrong with what I have done? The correct file is opened when I run the script, but none of the subsequent commands seem to execute. It just opens the document and then continues on to the reminders.

  • 1
    what is 'open filepath'? I don't think that line works and because it is in a 'try', the whole thing fails without getting a chance to display the dialog but also without comment. If I remove the 'try/error' lines, I get a 'variable filePath is not defined' error. Also, I don't think you have the syntax correct for the document/sheet/table. Try including the document among your 'tells'. – Mockman Oct 27 '19 at 15:23
  • 1
    In the code you've shown filePath is not defined, however, assuming it is and the document is actually opened then here are some issues: 1. There is nothing on in the on error handler to let you know what the error is. 2. Your are missing tell document 1 before tell sheet .... 3. display dialog value of cell "B4" needs to be: display dialog (get value of cell "B4") – user3439894 Oct 27 '19 at 15:39
1

Here is a simplified example, showing minimal code, to replicate what's shown in your OP, and as you can see in the Replies pane of Script Editor in the image further below there are no errors and both display dialog commands returned the expected value.

Numbers Document

enter image description here

Example AppleScript code:

set transferValue to 0

tell application "Numbers" to ¬
    tell table 1 of sheet 1 of document 1
        set transferValue to value of cell "B4"
        display dialog (get value of cell "B4")
        display dialog transferValue
    end tell 

Script Editor showing the results of running the code:

enter image description here

  • I got it to work now, thank you! – Luke Oct 29 '19 at 10:45

You must log in to answer this question.

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