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