AppleScript for Keynote exports

I have an application that builds and runs an AppleScript to export Keynote files to PowerPoint files in batches. I have everything working but the actual export command. The script is below:

					lines.Append " set current_file to POSIX file """ + Listbox1.Cell(i, 0) + """"
					lines.Append " set file_name to name of (info for current_file)"
					lines.Append " set dest_folder to POSIX path of """ + primaryDestPathLabel.text + "/"""
					lines.Append " set pptx_file to text 1 thru -5 of file_name & "".pptx"""
					lines.Append " set out_file to (dest_folder as Unicode text) & pptx_file"
					lines.Append " tell application ""Keynote"""
					lines.Append "    set thisdoc to open current_file"
					lines.Append "    delay 1"
					lines.Append "    display dialog out_file"
					lines.Append "    close access (open for access out_file)"
					'lines.Append "   export thisdoc to out_file as Microsoft PowerPoint"
					lines.Append "   close thisdoc saving no"
					lines.Append " end tell"

I have commented out the export line as you see above, because it doesn’t work. Can someone review and tell me how to fix this? I have tried for hours with no luck.

Thanks.

I have a laptop in my closet, but it doesn’t work.
Can you tell me how to fix it? I have tried for years with no luck.

We need more details about what’s happening.
Tell us what’s going on,
what’s happening instead,
things you have tried and what happened with that,
versions of Keynote and the OS [because Apple did change some of the scripting across Keynote versions],
have you successfully gotten the AppleScript to work not inside Xojo?

Also, totally unrelated, but no, I did not see the line you commented out because ' is a terrible comment mark it’s so hard to see! It’s a personal gripe though, I jest :slight_smile:

Hi Tim,

With the script above, I am able to open the file, present a dialog box showing the correct path to the out_file, create a ghost file to actually write the original file to, and close the file without issue. However, when I try to export the documents, the script will not write the actual file to the ghost file using the close access(open for access out_file).

I have tried using different formats of the export command, but nothing I have tried works.

I am using Mac OS Sierra (10.12.3) and Keynote (7.0.5). I haven’t tried using this exact format outside of Xojo, but other single Applescripts I created to do the same thing work fine.

I totally understand the issue with commenting out using the ', but that is what Xojo recommends, so that is what I use. :slight_smile:

I have no direct knowledge of how keynote handles export, but my first thought is there would be a problem if the file already existed. What happens if you just tell keynote to export the file with doing the opening first?

Hi Kevin,

Even without creating the ghost file first, the export command will not write out the file to destination path. It gets locked up on the first file and then closes.

The last time I was twiddling with AppleScripts to batch automate converting Pages to PDF I recall having to bend over backwards to deal with Pages being Sandboxed. Perhaps a sandboxing issue?

A sandboxed application cannot write to most standard folders by itself. That requires user interaction, ie Save box.

Try Documents. With some luck, Apple used a temporary entitlement to save there.

Hi All,

I have figured out the issue. I had to add a line of code related to identifying the POSIX file to work with before the export could happen.

Thanks to all for your assistance.

Roger