jraufeisen
jraufeisen

Reputation: 3877

Applescript: Export quicktime audio recording

With the following applescript, I try to

  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
    

Creating a new audio recording seems to be quite easy, but for some reason the export-command doesn't work. The error message says, that I don't have the permission to export it.

Upvotes: 3

Views: 3361

Answers (3)

bonh
bonh

Reputation: 2956

I found a solution to a related issue on the Apple Communities forum.

Instead of:

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

try separating the path components with a :, like:

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

Upvotes: 0

Simon White
Simon White

Reputation: 736

It does seem to be a sandboxing issue, but if you move the file path reference out of the QuickTime Player block and into a Finder block, it works. Also, your filename should end in “.m4a” not “.mp3” because QuickTime Player creates MP4 audio files (file extension “.m4a”) not MP3 audio files (file extension “.mp3.”)

So this version of your script works:

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

Upvotes: 3

user0721090601
user0721090601

Reputation: 5346

I ran into this error as well. There is a sandboxing issue. Try saving it instead to ~/Movies/ and your code should work okay. Then you can move it around using other commands to the folder you want it to be in.

Upvotes: 0

Related Questions