AppleScript:在QuickTime电影录制完成后自动保存录制结果

4
我正在尝试编写一个小的AppleScript项目,需要实现以下功能:
  • 开始QuickTime电影录制
  • 最小化录制窗口
  • 打开一个电影,使其全屏播放
  • 电影播放完毕后停止录制
  • 以"当前日期和时间"为文件名,在后台保存录制内容
  • 关闭电影播放器
  • 在Safari中打开一个网站
这是我目前已完成的部分:
set theDate to current date
set filePath to (path to desktop as text)

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

    tell newMovieRecording
        start
        tell application "QuickTime Player"
            set miniaturized of window 1 to true
        end tell
        tell application "QuickTime Player"
            open file "Users:test:Desktop:Movie.m4v"
            tell document "Movie.m4v" to play

            set the bounds of the first window to {0, 0, 1800, 1100} -- I did not find how to put the window in full screen (whatever the screen size is: I wrote this script on an external screen , but the project will take place on the screen of a laptop).
        end tell
        delay 160 -- the length of the movie
        save newMovieRecording in file (filePath) & theDate
        stop
        close newMovieRecording

        tell application "QuickTime Player"
            close document "Movie.m4v"
        end tell

    end tell
end tell

tell application "Safari"
    activate
    open location "http://stackoverflow.com"
end tell

上述脚本是我能够得到的:当电影录制应该保存时,苹果脚本编辑器会显示以下信息:“AppleScript错误 - QuickTime Player出现错误:无效的键形式。”
提前感谢任何帮助。

使用 present 来全屏播放您的电影(而不是 play)。 - user1804762
1个回答

1
您有几个问题需要解决。
  1. “file (filePath) & theDate” 可能是将“file (文件路径)”和日期拼接在一起,这会导致失败,因为它们不能连接。要解决此问题,请在保存之前创建文件路径,例如:

    set fileName to filePath & theDate save newMovieRecording in file fileName

  2. 然而,还有另一个问题:默认的日期格式包含冒号,而 Mac OS X 文件路径中不能使用冒号。您可能需要构建一个没有冒号的日期/时间戳,例如:

    set dateStamp to the year of theDate & "-" & the month of theDate & "-" & the day of theDate & " " & hours of theDate & "-" & minutes of theDate

  3. 文件名必须以正确的扩展名结尾,否则您将收到权限被拒绝的错误:

    set fileName to filePath & dateStamp & ".m4v"

(请注意,我在测试中使用了 .mov,希望它们的行为相同。)


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