I met an “Error 6” with exporting PDF from Keynote.app. It seems an error related with the Sandbox function.
tell application "Keynote"
set dCount to count every document
end tell
if dCount = 0 then
display dialog “There is no Keynote document" with icon 0 with title "No Document Error"
return
end if
tell application "Keynote"
set aPath to file of document 1
end tell
set curPath to (current application's NSString's stringWithString:(POSIX path of aPath))'s lastPathComponent()'s stringByDeletingPathExtension()'s stringByAppendingString:".pdf"
set tmpPath to (path to desktop) as string
set outPath to tmpPath & (curPath as string)
tell application "Keynote"
set anOpt to {class:export options, export style:IndividualSlides, all stages:false, skipped slides:true, PDF image quality:Best}
export document 1 to file outPath as PDF with properties anOpt —> Error 6
end tell
The solution is “touch” command before export. This works fine.
do shell script "touch " & quoted form of POSIX path of outPath
tell application "Keynote"
set anOpt to {class:export options, export style:IndividualSlides, all stages:false, skipped slides:true, PDF image quality:Best}
export document 1 to file outPath as PDF with properties anOpt
end tell