Error Getting Quicktime to record

I am trying to AppleScript Quicktime Player to record an audio recording and save it to a specific location. As I First try I modified a script I found to a simple one just to see if the concept worked.

set filePath to (path to desktop as text) & “test”
tell application “QuickTime Player”
set new_recording to (new audio recording)
tell new_recording
start
delay 10
stop
end tell
export (first document) in filePath using settings preset “Audio Only”
close (first document) without saving
end tell

How ever I keep getting the following Error in Quicktime player, which I don’t understand

“You don’t have permission to save the file “test.m4a”. You don’t have permission.”

How do I fix this

Please help

Model: macbook pro
AppleScript: 2.3.1
Browser: Safari 537.73.11
Operating System: Mac OS X (10.8)

change the first line to

you are right…
this works:
but

set filePath to (path to desktop as text) & “test.m4a”
set placetosaveFile to a reference to file filePath
tell application “QuickTime Player”
activate
set new_recording to (new audio recording)
– the name of document 1 becomes document “Audio Recording”
tell new_recording
start
delay 10
stop
end tell
set newRecordingDoc to first document whose name = “untitled”
export newRecordingDoc in placetosaveFile using settings preset “Audio Only”
close newRecordingDoc without saving
quit
end tell

now I can’t get Quicktime to quit without showing a dialog box about if I want to quit

Model: macbook pro
AppleScript: 2.3.1
Browser: Safari 537.73.11
Operating System: Mac OS X (10.8)


set filePath to (path to desktop as text) & "test.m4a"
delay 1
tell application "QuickTime Player"
	activate
	set new_recording to (new audio recording)
	tell new_recording
		start
		delay 10
		stop
	end tell
	
	open for access file filePath
	close access file filePath
	export (first document) in filePath using settings preset "Audio Only"
	close (first document) without saving
	ignoring application responses
		quit
	end ignoring
end tell

or


set placetosaveFile to (choose file name default name "file.m4a") as text
tell application "QuickTime Player"
	activate
	delay 1
	set new_recording to (new audio recording)
	-- the name of document 1 becomes document "Audio Recording"
	tell new_recording
		start
		delay 10
		stop
	end tell
	open for access file placetosaveFile
	close access file placetosaveFile
	set newRecordingDoc to first document whose name = "Ohne Titel"
	export newRecordingDoc in placetosaveFile using settings preset "Audio Only"
	close newRecordingDoc without saving
	ignoring application responses
		quit
	end ignoring
end tell
tell application "Finder"
	activate
	reveal placetosaveFile
end tell

thank you…

interestingly the first version still gave the dialog box while trying to quit and the second one did not???

Hmm

Both scripts are both now quitting with a dialog box. Interesting

Model: macbook pro
AppleScript: 2.3.1
Browser: Safari 537.73.11
Operating System: Mac OS X (10.8)