The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniOutliner > OmniOutliner 3 for Mac
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Export only a section of an outline...? Thread Tools Search this Thread Display Modes
Is it possible to export as opml a section of an outline?

I have a large body of work that I am outlining in OmniOutliner and would like to export pieces of it to Scrivener to continue drafting it. But when I go to export to opml (which Scrivener happily imports), I am forced to export the WHOLE outline, even if I select only certain rows.

I've tried to copy and paste, but it's not the same thing as importing in Scrivener. The results are not desirable.

Am I missing something? Or is there a script around that can export only sections of an outline? Or no one has thought of it, or needs it? :)

Thanks, R.
Have you tried Hoisting just the section you need?

Or, failing that, copying the pertinent sections to a new outline and exporting that?
You should, in principle, be able to do it with Applescript.

(The only obvious limitation is, if you have checked Automatically create attachments from typed URLs under Preferences > General any URLS that have been converted to gray lozenges).

The following quick draft aims to export any selected row(s) (and all the descendants thereof) to an OPML file. Note that if you have selected a parent row, there is no need to select any of its children or descendants - doing so will just cause a duplication in the export.

Rough first draft:
-- Indicative draft Ver 0.03 

-- Saves any subtree selected in OmniOutliner to an OPML file
-- Note that the whole sub-tree is copied, so only 'parent' elements need to be selected.

-- Disclaimer
-- This is just a rough draft of something which I have sketched for my own personal use, 
-- and which is provided purely as an illustration of possible approaches to coding.
-- You are free to adapt and reuse any part of it, without any warranties, implied
-- or explicit, as to its behaviour or suitability for use

-- Robin Trew	-	houthakker72 at gmail

-- ver 0.03 slightly modified to remove leading newline character, which choked some opml editors

property pOPMLHeadToExpand : "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<opml version=\"1.0\">
	<title>Selected in OO3</title>
property pOPMLHeadFromExpand : "</expansionState>

property pOPMLTail : "

property pNodeStart : "<outline "
property pLeafClose : "/>"
property pParentClose : "</outline>"

property pDate : date

on run
	set strOPML to MakeOPML(SelectedInOO())
	if strOPML ≠ "" then
		set oFile to choose file name with prompt "Save selected rows and their descendants as OPML" default name "Untitled.opml" default location (path to desktop) as alias
		WriteText2Path(strOPML, POSIX path of oFile)
	end if
end run

on MakeOPML(lstRows)
	if (length of lstRows > 0) then
		set {lngIndex, strExpand, strOutline} to my Rows2OPML(-1, lstRows, tab)
		set strOPML to pOPMLHeadToExpand & strExpand & pOPMLHeadFromExpand & strOutline & pOPMLTail
		return strOPML
		return ""
	end if
end MakeOPML

on Rows2OPML(lngIndex, lstRows, strIndent)
	set {strExpand, strOut} to {"", ""}
	repeat with oRow in lstRows
		set {strState, strName, strNote, lstCols, lstChiln} to oRow
		set strOut to strOut & pNodeStart & Attr("text", strName)
		if strState ≠ "" then set strOut to strOut & space & Attr("_status", strState)
		if strNote ≠ "" then set strOut to strOut & space & Attr("_note", strNote)
		repeat with oCol in lstCols
			set {strKey, strValue} to oCol
			if strValue ≠ "" then
				set strOut to strOut & my Attr(strKey, strValue)
			end if
		end repeat
		set lngIndex to lngIndex + 1
		if (length of lstChiln > 0) then
			set strExpand to strExpand & "," & (lngIndex) as string
			set {lngIndex, strSubExpand, strSubOutln} to Rows2OPML(lngIndex, lstChiln, strIndent & tab)
			if strSubExpand ≠ "" then set strExpand to strExpand & "," & strSubExpand
			set strOut to strOut & ">" & return & ¬
				strIndent & strSubOutln & return & ¬
				strIndent & pParentClose
			set strOut to strOut & pLeafClose & return
		end if
	end repeat
	if strExpand begins with "," and length of strExpand > 1 then set strExpand to text 2 thru -1 of strExpand
	return {lngIndex, strExpand, strOut}
end Rows2OPML

on Attr(strName, strValue)
	strName & "=" & EscapeChars(strValue)
end Attr

on EscapeChars(str)
	-- QUOTE < > & ETC
	set strEncoded to (do shell script "python -c 'import sys; from xml.sax.saxutils import quoteattr; print quoteattr(sys.argv[1])' " & ¬
		quoted form of str)
	set lstChars to characters of strEncoded
	repeat with i from 1 to length of lstChars
		set lngCode to id of item i of lstChars
		if lngCode > 127 then set item i of lstChars to ("&#" & lngCode as string) & ";"
	end repeat
	lstChars as Unicode text
end EscapeChars

on SelectedInOO()
	tell application id "OOut"
		if (count of documents) < 1 then return {}
		tell front document
			set lstSeln to selected rows as list
			set lngSeln to length of lstSeln
			if lngSeln < 1 then return {}
			-- GET THE NAMES AND TYPES OF ANY EXTRA COLUMNS (Beyond topic and note)
			set {idTopic, idNote} to {id of topic column, id of note column}
			tell (columns where id is not idTopic and id is not idNote)
				set {lstID, lstClass, lstName} to {id, type, name}
			end tell
			set lngUserCols to length of lstID
			repeat with iRow from 1 to lngSeln
				set item iRow of lstSeln to my Row2Node(item iRow of lstSeln, lngUserCols, lstID, lstClass, lstName)
			end repeat
		end tell
		return lstSeln
	end tell
end SelectedInOO

on Row2Node(oRow, lngUserCols, lstID, lstClass, lstName)
	tell application id "OOut"
		set strState to state of oRow
		if (strState ≠ checked) and (strState ≠ indeterminate) then
			set strState to ""
			set strState to strState as string
		end if
		set lstRow to {strState, topic of oRow, note of oRow}
		if lngUserCols > 0 then
			set lstCols to {}
			repeat with i from 1 to lngUserCols
				set varValue to value of cell id (item i of lstID) of oRow
				set cType to item i of lstClass
				if varValue is missing value then
					set varValue to ""
				else if cType = date then
					set varValue to short date string of varValue & space & time string of varValue
				else if cType = checkbox then
					if varValue = "checked" then
						set varValue to "2"
						set varValue to ""
					end if
				else if cType = duration then
					set varValue to ((varValue) as string) & "h"
				end if
				set end of lstCols to {item i of lstName, varValue as string}
			end repeat
			set end of lstRow to lstCols
			set end of lstRow to {}
		end if
		set refChiln to children of oRow
		if refChiln is missing value then
			set end of lstRow to {}
			set lstChiln to {}
			repeat with oChild in refChiln
				set end of lstChiln to my Row2Node(oChild, lngUserCols, lstID, lstClass, lstName)
			end repeat
			set end of lstRow to lstChiln
		end if
		return lstRow
	end tell
end Row2Node

on WriteText2Path(strText, strPosixPath)
	set f to (POSIX file strPosixPath)
	open for access f with write permission
	write strText as «class utf8» to f
	close access f
end WriteText2Path
Attached Files
File Type: zip oo3Seln2OPML.applescript (3.6 KB, 218 views)

Last edited by RobTrew; 2012-07-11 at 11:59 PM.. Reason: ver 3 - removed leading linefeed character from output
Wow, thanks for this script. But I get a syntax error:

Expected end of line, etc. but found “<”

Thank you for helping...

Copying and pasting code from these forms can be tricky if anything gets missed out.

I've added a zipped script file above – see if you still get an error with a download of that.


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to export Outline to Apple Pages hansdorsch OmniOutliner 3 for Mac 12 2012-10-02 09:02 AM
Export outline w/o Notes Column Mondozer OmniOutliner 3 for Mac 4 2012-03-15 08:56 AM
Omit unmarked section in LaTex export joaxi OmniOutliner 3 for Mac 0 2009-03-13 09:02 AM
Export Text from Outline Sidebar Dr Data OmniGraffle General 0 2008-05-13 07:17 AM
Numbered Outline Export Justin Chapman OmniOutliner 3 for Mac 1 2007-08-20 07:19 PM

All times are GMT -8. The time now is 03:51 PM.

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