Applescript Progress Bar结束时冻结,并在调用下一个例程时保持活动状态

时间:2016-06-14 16:59:39

标签: macos automation applescript

我正在制作一个自动化本地开发工作流程的Applescript。发生的事情是我在检查脚本依赖性(即MAMP)时使用Applescript进度条运行。进度条出现,动画完美,并返回我的例程,按预期检查依赖项。问题是,即使进度条达到其总步数,进度条也会冻结,即使脚本在以下例程中调用对话框,并且脚本冻结。

以下是启动进度条的例程:

on dependency_check()
    set progress description to "Access Granted: "
    set progress additional description to "Preparing..."

delay 0.5

set progress total steps to 100
repeat with i from 0 to 100
    try
        if i = 0 then
            set progress additional description to "Checking Dependencies..."
            delay 0.5
        else if (i > 0 and i < 10) then
            set progress additional description to "Checking Node.js..."
        else if i = 10 then
            set progress additional description to node_exists()
        else if (i > 10 and i ≤ 20) then
            set progress additional description to "Node.js is installed..."
        else if (i > 20 and i < 30) then
            set progress additional description to "Checking mamp-cli..."
        else if i = 30 then
            set progress additional description to mampcli_exists()
        else if (i > 30 and i ≤ 40) then
            set progress additional description to "mamp-cli is installed..."
        else if (i > 40 and i < 50) then
            set progress additional description to "Checking MAMP..."
        else if i = 50 then
            set progress additional description to mamp_exists()
        else if (i > 50 and i ≤ 60) then
            set progress additional description to "MAMP is installed..."
        else if (i > 60 and i < 70) then
            set progress additional description to "Checking Google Chrome..."
        else if i = 70 then
            set progress additional description to chrome_exists()
        else if (i > 70 and i ≤ 80) then
            set progress additional description to "Google Chrome is installed..."
        else if (i > 80 and i < 100) then
            set progress additional description to "All Dependencies Found..."
        else if i = 100 then
            set progress additional description to "Complete..."
            set progress completed steps to i
        end if

        set progress completed steps to i

        delay 0.025
    on error errTxt number errNum -- errTxt and errNum are returned from system
        display dialog errTxt & return & errNum

        exit repeat

    end try

end repeat

end dependency_check

应该注意的是,它在i = 10,30,50,70时调用其他例程。

如果找到依赖关系,它们都会返回文本。

以下是其中一个例程的示例:

on node_exists()
    set nodeExists to do shell script "test -e /usr/local/bin/node"
    if nodeExists is not "" then -- Verifies Node.js is installed by 'test' command
        beep
        tell application "Finder" to display dialog ¬
            "Node.js is not installed, and is needed to run this program. Download Node.js and try again." with title ¬
            "Required Library Missing: Node.js!" with icon caution ¬
            buttons {"Download Node.js", "Quit Program"} ¬
            default button 2 cancel button 2
        if button returned of result is "Download Node.js" then
            open location "https://nodejs.org/en/"
            script_exit()
        end if
    else
        return "Node.js is installed..."
    end if
end node_exists

提前感谢您的帮助。我完全卡住了!

0 个答案:

没有答案