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:
Code:
-- 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\">
<head>
<title>Selected in OO3</title>
<expansionState>"
property pOPMLHeadFromExpand : "</expansionState>
</head>
<body>
"
property pOPMLTail : "
</body>
</opml>"
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
-- BUILD OPML
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
else
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
else
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)
-- ENCODE DIACRITICS AND SPECIAL CHARACTERS
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
-- READ SELECTED OO3 ROWS TO NESTED APPLESCRIPT LISTS - Ver.04
on SelectedInOO()
tell application id "OOut"
if (count of documents) < 1 then return {}
tell front document
-- ANYTHING SELECTED ?
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
-- GATHER THE SELECTED ROWS AND THEIR CHILDREN INTO A NESTED LIST
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"
-- COLLECT VALUES FROM TOPIC AND NOTE
set strState to state of oRow
if (strState ≠ checked) and (strState ≠ indeterminate) then
set strState to ""
else
set strState to strState as string
end if
set lstRow to {strState, topic of oRow, note of oRow}
-- FROM ANY ADDITIONAL USER COLUMNS
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"
else
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
else
set end of lstRow to {}
end if
-- AND FROM ANY CHILDREN
set refChiln to children of oRow
if refChiln is missing value then
set end of lstRow to {}
else
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