2013-05-22 179 views
0

我做了一个监听某个端口的applescript。当它收到“开始”时,计算机开始从网络摄像头录制,当它收到“停止”时,它停止录制。正常退出applescript运行终端nc命令

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

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

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

on idle 
    --insert your code 
    beep 
    return 10 
end idle