0

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that's make sense, I'm use to "set var to :" with is not correct. perfect thank you !
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.