Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
The variable is not defined, but it is

I have declared global variables at the top of the script, and I have initialised them.

I can set the "do JavaScript" to the variable "emptyDue" fine. But then as soon as I try to compare the result of the JavaScript to the serviceDate variable, I get: "error "The variable emptyDue is not defined." number -2753 from "emptyDue"".

Why can I assign emptyDue on one line, and then on the very next line, it suddenly forgets that it should exist?

global emptyDue, serviceDate
set emptyDue to ""
set serviceDate to "2021-11-30"

on isEmptyDue()
    
    tell application "Safari" to tell document 1
        
        set emptyDue to do JavaScript "document.getElementById('trgUseNext').click();
 document.getElementById('trgUseNext').value; --gets the date value from a webpage."
        
        if emptyDue < serviceDate then
            display dialog "TRUE"
        else
            display dialog "FALSE"
        end if
        
    end tell
    
end isEmptyDue

isEmptyDue()
log emptyDue
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There is a known flaw in AppleScript’s design: it is possible for a command to return no value. If you then bind the result of that command to a variable, it effectively makes that variable undefined.

You can avoid that -2753 error by making sure your command always returns a value, even if that value is just an empty string.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!