我有一个从 plist 文件中提取的变量(这是我找到的将变量从一个脚本传递到另一个脚本的最佳方法)
工作正常,如果我随机执行“显示通知 var1”,我会得到正确的结果。
但是,如果我想在函数 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
我有这个错误
“变量 var1 未定义。该变量 var1 未定义。 (-2753)"
我该如何解决这个问题?提前谢谢你。
var1
在本地范围内。将其声明为属性:
property var1 : ""
或者将其声明为全局:
global var1
set var1 to ""
另一个变量
theDSIDFromPlist
没有出现在代码中。
我不确定您是否提供了所有相关代码。我无法完全重现您的问题。
我的方法是在脚本编辑器中调试脚本并添加一些 Try 块以实现更好的错误管理。
您的代码片段中既没有查询也没有定义相关变量,因此这实际上是任何人都可以为您做的事情。