使用Applescript控制Quicktime

时间:2020-04-03 10:54:39

标签: applescript quicktime

我正在寻找使用Applescript控制Quicktime的解决方案。 我需要做的只是- -打开快速时间并开始录制 -停止录制并将文件保存到设置的位置。

从以前的帖子中,我设法获得了以下内容。

    set theFilePath to "/Users/jamestebb/Desktop/01TestRecords/ " & "myfile" & ".mov"

tell application "QuickTime Player"
    set newMovieRecording to new movie recording
    tell newMovieRecording
        start
        delay 5
        pause
        save newMovieRecording in POSIX file theFilePath
        stop
        close newMovieRecording
    end 

这很好用,但是对于这个项目,我需要单独的脚本提示来开始和停止录制,而不是等待/延迟。

开始使用我的录音。

set theFilePath to "/Users/jamestebb/Desktop/01TestRecords/ " & "myfile" & ".mov"

tell application "QuickTime Player"
    set newMovieRecording to new movie recording
    tell newMovieRecording
        start

    end tell
end tell

这很好用,但是当我尝试使用以下内容停止录制时,出现了无法理解暂停的错误

set theFilePath to "/Users/jamestebb/Desktop/01TestRecords/ " & "myfile" & ".mov"

tell application "QuickTime Player"
    set MovieRecording to new movie recording
    tell MovieRecording

        pause
        save MovieRecording in POSIX file theFilePath
        stop
        close MovieRecording
    end tell
end tell

我猜这是因为当前正在录制的文件不再是“新电影录制”

任何想法很快就会解决?

1 个答案:

答案 0 :(得分:0)

我使用以下示例 AppleScript 代码测试了在 QuickTime中启动新电影录制播放器和第一个 script ,然后用第二个 script 处理,以暂停,保存,停止关闭

  • 请注意,这假定 QuickTime Player 正在运行,并且只有一个 New Movie Recording (新电影录制),并且没有打开任何其他 QuickTime Player 窗口。

脚本1:

tell application "QuickTime Player" to start (new movie recording)

脚本2:

set theFilePath to POSIX path of (path to movies folder) & "myMovie.mov"

tell application "QuickTime Player"
    tell document "Movie Recording"
        pause
        save it in POSIX file theFilePath
        stop
        close
    end tell
end tell

在这两个脚本之间,它成功在电影 文件夹中创建了 myMovie.mov 文件 我的首页 文件夹

测试是在 macOS High Sierra 下完成的。


注意:示例 AppleScript 代码就是这样,并且不包含任何错误处理视情况而定。用户有责任添加任何适当,需要或想要的错误处理。看看try中的error 声明AppleScript Language Guide 声明。另请参见Working with Errors。此外,在适当的情况下,例如,在事件之间,可能需要使用delay 命令delay 0.5,并适当设置了 delay value