AppleScript-AppleEvent处理程序失败

AppleScript-AppleEvent处理程序失败,applescript,quicktime,Applescript,Quicktime,我有一个脚本,在登录时,询问用户是否想看电影。在大多数情况下,它工作得很好。然而,有时由于未知的原因,我会遇到一个AppleeEvent处理程序失败的错误。我读过关于这个错误的其他帖子,但它们似乎都是独一无二的。所以,如果可能的话,请有人看看我的脚本,告诉我为什么偶尔会出现这种情况,如果我能做些什么来防止它 有一件事可能有助于了解,就是脚本中发生此错误时失败的一件事是电影无法播放。它会在quicktime中打开,但不会启动 提前谢谢,这是剧本 tell application "Welcome"

我有一个脚本,在登录时,询问用户是否想看电影。在大多数情况下,它工作得很好。然而,有时由于未知的原因,我会遇到一个AppleeEvent处理程序失败的错误。我读过关于这个错误的其他帖子,但它们似乎都是独一无二的。所以,如果可能的话,请有人看看我的脚本,告诉我为什么偶尔会出现这种情况,如果我能做些什么来防止它

有一件事可能有助于了解,就是脚本中发生此错误时失败的一件事是电影无法播放。它会在quicktime中打开,但不会启动

提前谢谢,这是剧本

tell application "Welcome" to activate
set question to display dialog "Would you like a welcome video?" buttons {"No, I've seen it", "Yes, please"} default button 2
set answer to button returned of question
if answer is equal to "Yes, please" then tell application "QuickTime Player"
    set theMovie to "Macintosh HD:Library:Desktop Pictures:Mac ML Opening Chalkbaord Video.mov"
    set openMovie to open theMovie
    present openMovie
    play openMovie
    delay 30
    quit
end tell
if answer is equal to "No, I've seen it" then tell application "Welcome"
    quit
    tell application "System Events"
        delete login item "Welcome"
    end tell
end tell

我的猜测是,你可能需要在电影开映和上映之间延迟一段时间。有时代码的运行速度比计算机的反应速度快。如果是这种情况,那么当代码告诉电影播放时,电影可能仍在尝试打开。。。这就是错误。因此,我添加了2个重复循环,在继续代码中的下一步之前,它会检查内容以确保它们可用。代码中还需要“打开文件”,而不仅仅是“打开”

您在if语句中告诉应用程序做某事的方法是不寻常的。我不会那么做的。我还将把您的if语句组合成一个if/else if语句。无论如何,下面是我编写代码的方法(我假设应用程序“欢迎”就是代码本身)。我希望这有帮助

set theMovie to "Macintosh HD:Library:Desktop Pictures:Mac ML Opening Chalkbaord Video.mov"

tell me to activate
set question to display dialog "Would you like a welcome video?" buttons {"No, I've seen it", "Yes, please"} default button 2
set answer to button returned of question

if answer is equal to "Yes, please" then
    tell application "QuickTime Player"
        activate
        set openMovie to open file theMovie

        -- delay until the movie opens
        set startTime to current date
        repeat until exists document 1
            delay 0.2
            if (current date) - startTime is greater than 10 then return -- a precaution so you don't get stuck in the repeat loop forever
        end repeat

        present openMovie
        play openMovie

        -- delay until the movie stops playing
        repeat until document 1 is not playing
            delay 1
        end repeat

        quit
    end tell
else if answer is equal to "No, I've seen it" then
    tell application "System Events" to delete login item "Welcome"
end if

那真是太棒了!但愿我能给你买杯咖啡或啤酒!正如你在我的剧本中所注意到的,我只知道有足够的危险性,因此不寻常的“如果”语句。谢谢,谢谢!!什么场合?某些上下文可以起到很大作用。当您对上下文和条件有了更深入的了解时,请准备好编辑您的问题。