使用AppleScript控制QuickTime

3

我正在寻找使用Applescript控制Quicktime的解决方案。 我所需要做的只有以下几点: - 打开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

我猜这是由于当前正在记录的文件不再是“新电影录制”所致。

有什么想法可以解决吗?


2个回答

2
我使用以下的AppleScript代码,测试用第一个脚本启动QuickTime PlayerNew Movie Recording,然后用第二个脚本进行暂停、保存、停止关闭
  • 请注意,这假定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代码仅供参考,并不包含任何适当的错误处理。用户需要根据需要添加适当的错误处理。请查看AppleScript语言指南中的try语句和error语句。另外,在事件之间可能需要使用delay命令,例如delay 0.5,延迟值应设置为适当的值。此外,请参阅“处理错误”。

0
脚本在我的老款Macbook Air上不起作用,特别是对于较长时间的录音。

因此,我了解到了“sox”(这仅适用于音频录制)。我使用Applescript并将其与终端录音集成。请使用Control + C中止录制。

tell application "System Events"
    tell application "Terminal" to activate
    delay 1
    repeat 2 times
        delay 2
        key code 8 using {control down}
    end repeat

结束告诉

Mac 上与 arecord 命令相当的命令是什么?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接