Applescript: 导出QuickTime音频录制

3
使用以下的 AppleScript,我试图:
  1. record the audio with "QuickTime Player" for several seconds

  2. export the track and save it to the desktop

    tell application "QuickTime Player"
      launch
    
      set doku to new audio recording
      start doku
      delay 4
      stop doku
      set savePath to "~/Desktop/record.mp3"
      set newDoc to last item of (documents whose name contains "Untitled")
      export newDoc in file savePath using settings preset "Audio Only"
    
    end tell
    

创建新的音频录制似乎很容易,但由于某些原因导出命令无法正常工作。错误消息显示我没有导出权限。

3个回答

3

似乎是沙盒问题,但如果将文件路径引用移出QuickTime Player块并移到Finder块中,它就可以正常工作。此外,您的文件名应以“.m4a”结尾而不是“.mp3”,因为QuickTime Player创建的是MP4音频文件(文件扩展名为“.m4a”),而不是MP3音频文件(文件扩展名为“.mp3”)。

因此,您脚本的这个版本是有效的:

tell application "Finder"
    set savePath to (the path to the desktop folder as text) & "record.m4a"
    tell application "QuickTime Player"
        activate
        set doku to new audio recording
        start doku
        delay 4
        stop doku
        set newDoc to last item of (documents whose name contains "Untitled")
        export newDoc in file savePath using settings preset "Audio Only"
    end tell
end tell

0

我也遇到了这个错误。这是一个沙盒问题。尝试将其保存到〜/Movies/,您的代码应该可以正常工作。然后您可以使用其他命令将其移动到想要的文件夹中。


似乎是个好主意,但无论如何对我都没用……不过还是谢谢你的回答! - jraufeisen

0

我在苹果社区论坛上找到了一个相关问题的解决方案

而不是:

set savePath to "~/Desktop/record.mp3"

尝试使用:分隔路径组件,例如:

set savePath to "Macintosh HD:Users:<your username>:Desktop:record.mp3"

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