我尝试从tell块调用函数/处理程序,但AppleScript不断抛出错误:
结果:错误" AppleEvent处理程序失败。"数字-10000
脚本失败,我打电话给 start_varnish():
tell application "System Events"
set iTermIsRunning to exists (processes where name is "iTerm")
end tell
tell application "iTerm"
activate
try
tell current terminal
if iTermIsRunning then
launch session "Default Session"
end if
tell the last session
my start_varnish()
end tell
end tell
on error err
log "Reopening iTerm2"
reopen
tell current terminal
tell the last session
my start_varnish()
end tell
end tell
end try
end tell
on start_varnish()
set name to "Varnish Cache"
end start_varnish
当我移动处理程序的内容并将其直接放在上面的代码中时,它工作正常,但我想将功能包装在处理程序中以便重用。
答案 0 :(得分:0)
我能找到的最接近的修复方法如下:
tell application "System Events"
set iTermIsRunning to exists (processes where name is "iTerm")
end tell
tell application "iTerm"
activate
try
tell current terminal
if iTermIsRunning then
launch session "Default Session"
end if
my start_varnish()
end tell
on error err
log "Reopening iTerm2"
reopen
my start_varnish()
end try
end tell
on start_varnish()
tell application "iTerm"
tell current terminal
tell the last session
set name to "Varnish Cache"
end tell
end tell
end tell
end start_varnish
我不确定 start_varnish的上下文中是否理解单元当前终端和告诉上一个会话的原始问题中的作用域)处理程序。