AppleScript+;Quicktime:启动和停止电影录制并将其导出到磁盘

AppleScript+;Quicktime:启动和停止电影录制并将其导出到磁盘,applescript,quicktime,Applescript,Quicktime,正在尝试启动屏幕录制,请等待几秒钟,停止录制并将保存的录制导出到磁盘 版本 AppleScript 2.2.4 快速时间:10.2 AppleScript set filePath to "" & (path to desktop) tell application "QuickTime Player" set newMovieRecording to new movie recording tell newMovieRecording start

正在尝试启动屏幕录制,请等待几秒钟,停止录制并将保存的录制导出到磁盘

版本

  • AppleScript 2.2.4
  • 快速时间:10.2
AppleScript

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
停止和启动命令工作正常,但导出命令失败,出现以下错误:

movie_record.scpt:215:294: execution error: QuickTime Player got an error: Can’t get document "Movie Recording". (-1728)

请注意,在发出stop命令后,文档的名称将发生更改

set filePath to (path to desktop as text) & "movie.mov"

tell application "QuickTime Player"
    set newMovieRecording to new movie recording
    set windowID to id of first window whose name = "Movie Recording"

    tell newMovieRecording
        start
        delay 2 --(seconds)
        stop
    end tell

    set newMovieRecordingDoc to first document whose name = (get name of first window whose id = windowID)
    tell newMovieRecordingDoc to export in filePath using settings preset "iPod"
    --tell newMovieRecordingDoc to export in filePath using settings preset "25 fps"
end tell

找到了解决办法。请注意,从调用脚本到录制实际开始,有一个轻微的延迟(约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.mov' 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
(*********************************************
录制一部“QuickTime”电影
Args:
1.名称:电影的名称。
2.秒:要录制的电影的长度(以秒为单位)。
用法:
>osascript movie_record.scpt'name.mov'5
>osascript movie_record.scpt
**********************************************)
运行argv
将movieName设置为argv的项目1
将delaySeconds设置为argv的项目2
将文件路径设置为(桌面路径为文本)&movieName
将f设置为对文件路径的引用
告诉应用程序“QuickTime Player”
设置newMovieRecording to new movie recording
告诉NewMovierRecording
开始
延迟秒
暂停
在f中保存newMovieRecording
停止
关闭新电影录制
结束语
结束语
终点

我运行了建议的代码块,虽然
导出
命令没有抛出错误,但QuickTime没有将任何内容保存到磁盘,录制窗口仍然打开。您能否验证QuickTime是否将文件保存到Mac上的指定位置?我在Snow Leopard中编写并测试了它。今晚我可以查看最新版本。你能解释一下
保存
导出
之间的区别吗?我需要先打一个电话吗?我已经在filePath中保存了新的MovieRecording(它调出了这个对话框:),但是文件仍然没有被“保存”到磁盘。在Mountain Lion中,我甚至在解析了文档引用之后,通过将其简单地引用为文档1,就得到了一个错误。它给了我一个“我想录制”屏幕,直到终端命令的执行结束(希望立即增强功能)如果我通过更改脚本给出路径而不是文件名,您能否帮助我获得sameI被拒绝保存的权限