The Omni Group Forums

The Omni Group Forums (
-   AppleScripting Omni Apps (
-   -   Export file OO4 (

random1destiny 2014-03-11 07:17 AM

Export file OO4
Hey, applescript newbie here. I'm trying to write a script that will export my OO4 file to a specified format and location. In the Omnioutliner applescript dictionary I found:

[QUOTE]export v : Exports the document to the specified location and file type. Unlike the "save" command, this will never set the name of the document or change its modified flag.
export specifier : the object for the command
to file : Where to place the exported document.
[as text] : The name of a writable file type to use when writing the document. Defaults to the appropriate type for the path extension on the export destination.[/QUOTE]

And based on that I made a few attempts:

[CODE]tell application "OmniOutliner"
export to "/Users/mm/Dropbox/My Stuff/Outliner export" as ".rtf"
end tell[/CODE]

Did nothing.

[CODE]tell application "OmniOutliner"
tell front document
export to "/Users/mmarotta/Dropbox/My Stuff/Outliner export/Sell house (conflict from Macbook-Pro-Michael-Marotta).oo3"
end tell
end tell

Gave error message "error "OmniOutliner got an error: “Sell house (conflict from Macbook-Pro-Michael-Marotta).oo3” couldn’t be moved because you don’t have permission to access “Outliner export”." number 7"

[CODE]tell application "OmniOutliner"
set mydoc to open "/Users/mmarotta/Documents/My Local Stuff/OmniPresence/Outliner Notes Files/Outline Projects/Sell house.oo3"
export mydoc to "/Users/mmarotta/Dropbox/My Stuff/Outliner export/Sell house.oo3" as ".rtf"
end tell

Said .rtf is not a writable format. I tried ".rtf", "RTF", "RTF (Rich Text Document)", "HTML", and "com.omnigroup.OmniOutliner.HTMLExport/HTML (Dynamic)" (which I saw used in another post) and all got the similar error. I'm not really sure what's supposed to go in here.

When I tried removing the 'as .rtf' section hoping it would just default to something to see if the rest of the script worked I got "error "OmniOutliner got an error: “Sell house.oo3” couldn’t be moved because you don’t have permission to access “Outliner export”." number 7"

I just can't get any of this to work. Like I said, I'm super new to applescript so it's probably something obvious but I'm not really sure where to go from here.


Ken Case 2014-03-11 02:57 PM

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 [URL=""]Mountain Lion's AppleScript Release Notes[/URL] 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, [FONT="Courier"]file "Macintosh HD:Users:me:sample.txt"[/FONT], [FONT="Courier"]POSIX file "/Users/me/sample.txt"[/FONT], or the result of [FONT="Courier"]choose file[/FONT] would all be acceptable, but the string [FONT="Courier"]"/Users/me/sample.txt"[/FONT] would not.[/QUOTE]

So, all you need to do to solve this is to turn the string into a file reference [I]before[/I] 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[/CODE]

Hope this helps!

random1destiny 2014-03-12 02:04 PM

Yes, that worked perfectly! Thanks Ken!

All times are GMT -8. The time now is 07:01 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.