![AppleScript + Quicktime:开始和停止电影录制并将其导出到磁盘](https://linux22.com/image/1368391/AppleScript%20%2B%20Quicktime%EF%BC%9A%E5%BC%80%E5%A7%8B%E5%92%8C%E5%81%9C%E6%AD%A2%E7%94%B5%E5%BD%B1%E5%BD%95%E5%88%B6%E5%B9%B6%E5%B0%86%E5%85%B6%E5%AF%BC%E5%87%BA%E5%88%B0%E7%A3%81%E7%9B%98.png)
尝试开始屏幕录制,等待几秒钟,停止录制并将保存的录制导出到磁盘。
版本
- AppleScript 2.2.4
- QuickTime:10.2
苹果脚本
set filePath to "" & (path to desktop)
tell application "QuickTime Player"
set newMovieRecording to new movie recording
tell newMovieRecording
start
delay 2 --(seconds)
stop
export newMovieRecording in (filePath & "movie") using settings preset "25 fps"
end tell
end tell
停止和启动命令工作正常,但export
命令失败并出现以下错误:
movie_record.scpt:215:294: execution error: QuickTime Player got an error: Can’t get document "Movie Recording". (-1728)
答案1
找到了解决方案。请注意,从调用脚本到实际开始录制之间会有轻微的延迟(大约 2 秒)。
(*********************************************
Record a Single `QuickTime` Movie
Args:
1. name: The name of the movie.
2. seconds: The length of the movie you want to record in seconds.
Usage:
> osascript movie_record.scpt 'name' 5
> osascript movie_record.scpt <file_name> <seconds>
**********************************************)
on run argv
set movieName to item 1 of argv
set delaySeconds to item 2 of argv
set filePath to (path to desktop as text) & movieName
set f to a reference to file filePath
tell application "QuickTime Player"
set newMovieRecording to new movie recording
tell newMovieRecording
start
delay delaySeconds
pause
save newMovieRecording in f
stop
close newMovieRecording
end tell
end tell
end run