【问题标题】:Trying to open, modify, and save files in Quicktime with AppleScript尝试使用 AppleScript 在 Quicktime 中打开、修改和保存文件
【发布时间】:2016-03-08 09:39:09
【问题描述】:

我没有成功尝试使用 AppleScript 来自动化对一堆文件进行小幅编辑的过程。更具体地说,我想要一个脚本:

  1. 在 QuickTime 中打开特定文件
  2. 将其拆分为指定长度的段
  3. 以与原始文件相同的格式和质量将每个片段保存为单独的文件。
  4. 关闭文档

最重要的是,我希望脚本基本上可以在无人协助/无人的情况下运行。

这里有一些关于我正在尝试做的事情的更多信息:http://hints.macworld.com/article.php?story=20100305070247890

不久前 StackOverflow 上的另一个用户 asked a similar question,但该建议不起作用。

从我能找到的几个在线讨论中,Apple 似乎在版本 7 之后取消了 QuickTime 的一些功能。我目前使用的是 10.3+

Here's another discussion 几乎完全描述了我正在尝试做的事情。正如“kryten2”所指出的,导出似乎不再适用于新版本的 QuickTime。而且,就像“VideoBeagle”一样,当我尝试调用 save 方法时出现权限错误。

VideoBeagle 在该页面上发布的代码对我不起作用。这是修改后的版本:

tell application "QuickTime Player"
    open basefile --argument passed to script when executed

    set the clipboard to "outputfile"
    delay (0.25)
    tell document 1
        trim from 0 to 60
        tell application "System Events"
            tell process "QuickTime Player"
                keystroke "s" using command down
                keystroke "v" using command down
                delay 1
                keystroke return
                delay 3
                #click menu item "Save..." of menu "File" of menu bar 1
            end tell
        end tell

        close saving no

    end tell
end tell

上面的代码确实在 QuickTime 中打开文件并将文件修剪到正确的长度,但随后它会在新窗口中创建文件的未保存副本,关闭原始文件,但不保存新文档。当我尝试延迟并删除“修剪”功能时,它会显示“保存”对话框,但实际上不会保存文件。

有没有人成功地使用 AppleScript 和 QuickTime 来保存文件? ...最近?

非常感谢!

【问题讨论】:

    标签: applescript quicktime


    【解决方案1】:

    如果你有 QuickTime Pro 的授权,最好使用 QuickTime Player 7 的导出功能(不是免费的,但很便宜)。为此,您还需要从 Apple 网站下载这个旧的 QT 版本。它仍然可用,但 Apple 推广的 QuickTime Player 7 基本上只有读取功能。

    如果您想坚持使用 QuickTime Player(版本 7 之后),在保存时编写脚本存在已知问题。解决方法是像您已经开始那样模拟 GUI 的一部分。

    下面的脚本要求处理电影文件,定义修改后的视频的新路径和名称,从第 2 秒修剪到第 6 秒,然后使用 GUI 界面保存并关闭。我制作了许多 cmets 以确保您可以根据自己的需要理解和更新:

    -- select file to be processed
    set myVideo to choose file with prompt "Select video to be processed"
    
    -- set new path and file name
    set newPath to ((path to desktop folder from user domain) as string) & "Test_Folder"
    set PPath to POSIX path of newPath
    set newName to "cutVideo.mov"
    
    tell application "QuickTime Player"
    activate
    open myVideo
    set myDoc to front document
    trim myDoc from 2 to 6  -- keep only video from second 2 to 6
    end tell
    tell application "System Events"
    tell process "QuickTime Player"
        keystroke "s" using {command down}
        delay 0.8
        keystroke "G" using {command down} -- go to
        delay 0.8
        keystroke PPath -- folder path with / and not :
        delay 0.8
        keystroke return
        delay 0.8
        keystroke newName -- fill file name
        delay 0.8
        keystroke return -- ok save dialog
        delay 0.8
        keystroke "w" using {command down} -- close window
    end tell
    end tell
    

    【讨论】:

    • 感谢您的回复,pbell!我一直不愿意回到 QT7,因为我发布的论坛主题上的用户在他们的实验中没有成功。模拟 GUI 似乎是一种非常麻烦的、有时不一致的方法(但它可能是唯一的方法)。我能够让你的代码工作(谢谢!),虽然我不得不在修剪后添加延迟......我假设菜单项没有足够快地重新启用并且 QuickTime 不接受“s”键击。
    • 很高兴它解决了您的问题。我尝试了许多其他方法来避免使用 QT GUI 进行保存和导出,但总是失败。在 GUI 脚本中,所需的延迟来自硬件速度、操作系统版本以及其他进程是否在后台运行。这就是为什么最好设置安全高值......
    • 我不得不承认,在使用您提供的代码又玩了一个小时之后,我无法让它始终如一地正确执行。我怀疑/假设这是因为您提到的因素(硬件、流程等)。有时它不会激活 QT 窗口,因此击键被发送到其他地方(在trim 似乎 之后调用activate 来解决这个问题..??),有时keystroke newName 不会发生所以文件被命名为“无标题”等。哎呀!我可能只需要增加延迟大小并在新保存的文件工作时对其进行监控。再次感谢!
    • 从价值案例开始,设置延迟为 2,然后您应该能够在屏幕上看到所有步骤。当然,请记住,因为您使用的是 GUI 脚本,所以在运行期间您不应该触摸键盘或鼠标!该脚本非常适合我。最后但并非最不重要的一点是,您是否在桌面上创建了文件夹“Test_Folder”(参见脚本的第 4 行):它必须存在(或者您可以更改脚本中的行)
    猜你喜欢
    • 2022-08-05
    • 1970-01-01
    • 1970-01-01
    • 2015-10-03
    • 1970-01-01
    • 2021-09-08
    • 2021-12-05
    • 2015-11-30
    • 1970-01-01
    相关资源
    最近更新 更多