AppleScript:未定义变量
AppleScript : variable is not defined
我有一个从 plist 文件中提取的变量(这是我想出的将变量从一个脚本传递到另一个脚本的最佳方式)
它工作正常,如果我随机 "display notification 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
我有这个错误
"The variable var1 is not defined. The variable
var1 is not defined. (-2753)"
我该如何解决这个问题?提前谢谢你。
我不确定您是否提供了所有相关代码。我无法完全重现您的问题。
我的方法是在脚本编辑器中调试脚本并添加一些 Try 块以更好地管理错误。
您的代码段中既没有查询也没有定义相关变量,所以这真的是任何人都可以为您做的。
干杯,拉尔夫
var1
在本地范围内。声明为 属性:
property var1 : ""
或者将其声明为全局:
global var1
set var1 to ""
另一个变量theDSIDFromPlist
没有出现在代码中。
我有一个从 plist 文件中提取的变量(这是我想出的将变量从一个脚本传递到另一个脚本的最佳方式)
它工作正常,如果我随机 "display notification 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
我有这个错误
"The variable var1 is not defined. The variable var1 is not defined. (-2753)"
我该如何解决这个问题?提前谢谢你。
我不确定您是否提供了所有相关代码。我无法完全重现您的问题。
我的方法是在脚本编辑器中调试脚本并添加一些 Try 块以更好地管理错误。
您的代码段中既没有查询也没有定义相关变量,所以这真的是任何人都可以为您做的。
干杯,拉尔夫
var1
在本地范围内。声明为 属性:
property var1 : ""
或者将其声明为全局:
global var1
set var1 to ""
另一个变量theDSIDFromPlist
没有出现在代码中。