With the following applescript, I try to
record the audio with "QuickTime Player" for several seconds
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.
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