Kevin
Kevin

Reputation: 1106

AppleScript : variable is not defined

I have a variable extracted from a plist file (that the best way I figure out for passing variable from one script to a another)

It's work fine, if I do a random "display notification var1" I have the correct result.

However if I want to pass the variable in a fonction ex.

set var1 to ""
set the plistfile_path to "~/Desktop/_DATA.plist"

tell application "System Events"
    set p_list to property list file (plistfile_path)
    -- read the plist data

    set var1 to value of property list item "DSID" of p_list as text
end tell

[...]

on makeStatusBar()
    set bar to current application's NSStatusBar's systemStatusBar

    set StatusItem to bar's statusItemWithLength:-1.0

    -- set up the initial NSStatusBars title
    StatusItem's setTitle:var1
    -- set up the initial NSMenu of the statusbar
    set newMenu to current application's NSMenu's alloc()'s initWithTitle:"Custom"

    newMenu's setDelegate:me (*
    Requied delegation for when the Status bar Menu is clicked  the menu will use the delegates method (menuNeedsUpdate:(menu)) to run dynamically update.


    *)

    StatusItem's setMenu:newMenu

end makeStatusBar

I have this error

"The variable var1 is not defined. The variable var1 is not defined. (-2753)"

How can I fix this? thank you in advance.

Upvotes: 0

Views: 5864

Answers (2)

Ralf Bertling
Ralf Bertling

Reputation: 29

I am unsure if you provided all relevant code. I could not quite reproduce your problem.

My approach would be debugging the Script in Script Editor and add some Try blocks for better error management.

The variable in question is neither queried nor defined in your snippet, so this is really all anyone can do for you.

Upvotes: 1

vadian
vadian

Reputation: 285180

var1 is in local scope. Declare it as property:

property var1 : ""

Alternatively declare it as global:

global var1
set var1 to ""

The other variable theDSIDFromPlist doesn't appear in the code.

Upvotes: 2

Related Questions