08.01.07

OmniOutliner to folder structure

Posted in AppleScript, Macintosh, OmniOutliner at 2:55 am by Lazra

An other useless AppleScript. OmniOutliner seems to be bundled with all new Apple computers. My idea is: Create a hierarchical structure in OO related to some kind of a project and export this to a folder structure in the filesystem to fill it with any kind of information.
The script exports a OPML file from OO to home/scriptfiles/ and reads the XML information out of it. It asks you for a folder to export the sub- and sub-sub… folders there. The OPML file stays, the script could be told to delete it. I like to stay.
I want to thank Skeeve who helped me with the handler which creates the folders. Just in case he reads this…..


on run

set inbetween to POSIX path of (path to home folder) & "scriptfiles/"

tell application "Finder"
try
make new folder at ((home as text)) with properties {name:"scriptfiles"}
end try
end tell

tell application "OmniOutliner"
export document 1 to inbetween & "oo.opml" as "OOOPMLDocumentType"

set selected_path to (choose folder) as string
set destination to POSIX path of selected_path

end tell

tell application "System Events"
set XMLfile to XML file (inbetween & "oo.opml")
set root to XML element 1 of XMLfile
set body to XML element "body" of root
my make_structure(body, destination)
end tell

end run

to make_structure(parent, current_path)
set done to false
tell application "System Events"
repeat with elt in (every XML element of parent whose name is "outline")
my make_structure(elt, current_path & (value of XML attribute "text" of elt) & "/")
set done to true
end repeat
end tell
if not done then
do shell script "mkdir -p " & quoted form of current_path
end if
end make_structure