正常退出applescript运行终端nc命令

时间:2013-05-22 07:24:43

标签: applescript

我制作了一个听取某个端口的AppleScript。当它收到“开始”时,计算机开始从网络摄像头录制,当它收到“停止”时,它停止录制。

现在的问题是我总是要强行退出这个应用程序。由于重复声明?有没有办法规避这个?我读了一些关于空闲处理程序的内容,但是我的应用程序继续运行很重要(没有用户点击等)。

set recording to 0
repeat
set test to (do shell script "nc -l 2700") as string

if test = "start" and recording = 0 then
    tell application "QuickTime Player"
        activate
        new movie recording
        document "Movie Recording" start
        set recording to 1
        delay 2
    end tell
else if test = "stop" and recording = 1 then
    tell application "QuickTime Player"
        document "Movie Recording" stop
        set pad to path to desktop folder as string
        set naam to (do shell script "date +%s") as integer
        set extension to ".mov"
        set all to pad & naam & extension
        export document "Untitled" in file all using settings preset "720p"
        delay 1
        close document "Untitled" saving no
        set recording to 0
    end tell
end if
end repeat

1 个答案:

答案 0 :(得分:0)

idle handler你是对的。 return语句指定在调用处理程序之前应经过的秒数。确保将脚本保存为保持打开的应用程序。

on idle
    --insert your code
    beep
    return 10
end idle
相关问题