0

我制作了一个监听某个端口的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
4

1 回答 1

0

关于空闲处理程序,您是对的。return 语句指定在调用处理程序之前应该经过多少秒。确保将脚本保存为保持打开的应用程序。

on idle
    --insert your code
    beep
    return 10
end idle
于 2013-05-22T11:31:16.783 回答