【问题标题】:AppleScript + Quicktime: Start and stop a movie recording and export it to diskAppleScript + Quicktime:开始和停止电影录制并将其导出到磁盘
【发布时间】:2013-06-24 02:33:16
【问题描述】:

尝试开始屏幕录制,等待几秒钟,停止录制并将保存的录制导出到磁盘。

版本

  • AppleScript 2.2.4
  • QuickTime: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

停止和启动命令正常工作,但 export 命令失败并出现此错误:

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

【问题讨论】:

    标签: applescript quicktime


    【解决方案1】:

    请注意发出停止命令后文档名称发生变化...

    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
    

    【讨论】:

    • 我运行了您建议的代码块,虽然 export 命令没有引发错误,但 QuickTime 没有将任何内容保存到磁盘并且录制窗口仍然打开。您能否验证 QuickTime 是否将文件保存到您 Mac 上的指定位置?
    • 我在 Snow Leopard 中编写并测试了它。我今晚可以查看最新版本。
    • 你能解释一下saveexport之间的区别吗?我需要先打电话给另一个吗?我有save newMovieRecording in filePath 工作(它拉起这个对话:cl.ly/image/0s3O0r0D0c1c),但文件仍然没有被“保存”到磁盘。
    • 在 Mountain Lion 中,即使通过简单地将文档引用称为文档 1 来解决文档引用,我也会收到错误消息。它给了我一个 permission error
    【解决方案2】:

    找到了解决办法。请注意,从调用脚本到录制实际开始之间会有轻微的延迟(大约 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
    

    【讨论】:

    • 我想记录屏幕直到我的终端命令执行结束(想立即增强功能)你能帮我做同样的事情吗
    • 如果我通过更改脚本给出路径而不是文件名,我会被拒绝保存
    猜你喜欢
    • 2022-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多