-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsheet_to_opml.applescript
112 lines (95 loc) · 3.77 KB
/
sheet_to_opml.applescript
1
-- Explode text of selected DTPO sheets to OPML for Tinderbox:-- For selected sheets, each sheet becomes an OPML entity-- and sheet rows become children.-- Column titles become OPML attributes-- "Name," "Text" and "_note" are significant for Tinderbox-- Based on the work of Korm and Christian Grunenberg: thanks!-- Use as you like, but don't blame us if you destroy your data.-- If you finds bugs/issues/trouble, please send-- the source files that don't convert correctly to:-- Charles Turner <[email protected]>-- Version 0.01-- 29 April 2010set theOpen to "<outline "set theClose to "/>"on opmlify(str) set numChars to length of str set escapedStr to "" repeat with i from 1 to numChars set char to character i of str if char is equal to ">" then set escapedStr to escapedStr & ">" else if char is equal to "<" then set escapedStr to escapedStr & "<" else if char is equal to "&" then set escapedStr to escapedStr & "&" else if char is equal to "\"" then set escapedStr to escapedStr & """ else if char is equal to (ASCII character 10) then set escapedStr to escapedStr & " " else if char is equal to (ASCII character 9) then set escapedStr to escapedStr & "	" else set escapedStr to escapedStr & char end if end repeat return escapedStrend opmlifytell application id "com.devon-technologies.thinkpro2" set this_database to current database set these_items to the selection if these_items is {} then error "Please select some contents" set thisFileName to choose file name with prompt "Export" default name (name of this_database as string) & ".opml" set theOPML to "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " & return set theOPML to theOPML & "<opml version=\"1.0\">" & return set theOPML to theOPML & "<head>" & return set theOPML to theOPML & "<title>" & (name of this_database as string) & "</title>" & return set theOPML to theOPML & "</head>" & return set theOPML to theOPML & "<body>" & return -- This could actually show progress: show progress indicator "Creating OPML..." repeat with j in these_items -- Get the record attributes: -- You can add more following these examples. -- Note trailing space. set theLocation to "Location=\"" & my opmlify(location of j) & "\" " set rawName to my opmlify(name of j) set theName to "text=\"" & rawName & "\" " set theComment to "DTcomment=\"" & my opmlify(comment of j) & "\" " -- These shouldn't need to be opmlified? set theDtUrl to "DTurl=\"" & "x-devonthink-item://" & uuid of j & "\" " set theOrigUrl to "OriginalUrl=\"" & URL of j & "\" " -- Do the tags: set theTags to "" set tagList to tags of j repeat with t in tagList set theTags to theTags & t & ";" end repeat set theTags to "DTtags=\"" & my opmlify(theTags) & "\" " -- Start the document entry: set theOPML to theOPML & theOpen & theName & theLocation & theComment & theDtUrl & theOrigUrl & theTags & ">" & return -- Explode the "text" set theCols to columns of j set numCols to count of theCols set theSheet to cells of j set numRows to count of theSheet repeat with k from 1 to numRows set theRow to "" repeat with m from 1 to numCols set theRow to theRow & item m of theCols & "=\"" & my opmlify(item m of item k of theSheet) & "\" " end repeat set theEntry to theOpen & theRow & theClose set theOPML to theOPML & theEntry & return end repeat -- Close the document entry: set theOPML to theOPML & "</outline>" & return end repeat set theOPML to theOPML & "</body>" & return & "</opml>" hide progress indicator set theFile to open for access thisFileName with write permission if (get eof of theFile) > 0 then set eof of theFile to 0 end if write theOPML as «class utf8» to theFile close access theFileend tell