【问题标题】:Calling AppleScript handler from tell block从 tell 块调用 AppleScript 处理程序
【发布时间】:2015-07-20 15:14:43
【问题描述】:

我正在尝试从 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

当我移动处理程序的内容并将其直接放在上面的代码中时,它可以正常工作,但我想将功能包装在处理程序中以实现可重用性。

【问题讨论】:

    标签: applescript iterm2


    【解决方案1】:

    我能找到的最接近的修复方法如下:

    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( ) 处理程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 2020-10-03
      • 2011-09-27
      • 1970-01-01
      相关资源
      最近更新 更多