Thread: Export file OO4
View Single Post
You're on the right track!

The issue you're running up against is that you're passing a string to the export command where it expects a file reference. AppleScript is generally pretty clever about automatically converting strings to file references when it can, so it does—which is why you don't get a type error—but the reference is pointing outside the app's sandbox, so you get a permission error.

Here is what Mountain Lion's AppleScript Release Notes has to say about all this:

Quote:
When sending commands to a sandboxed application, such as TextEdit in OS X Mountain Lion, parameters that refer to files must be of an explicit file-like type and not a bare string, or the target application will not be able to access the file. For example, file "Macintosh HD:Users:me:sample.txt", POSIX file "/Users/me/sample.txt", or the result of choose file would all be acceptable, but the string "/Users/me/sample.txt" would not.
So, all you need to do to solve this is to turn the string into a file reference before handing it off to the app, so that the sandbox will see that the script has granted the app access to that path. Like so:

Code:
tell application "OmniOutliner"
	tell front document
		export to POSIX file "/tmp/test1.rtf"
	end tell
	export front document to POSIX file "/tmp/test2.rtf"
end tell
Hope this helps!