View Single Post
Code:
--Exports all oo3 files in folder and exports to desired folder. v1
--Instructions:
--Edit paths to your outline and export folder (put export folder in your Dropbox/Google Drive or similar account to access these on iphone or any computer without omnioutliner)
--Edit both output file extension as well as export file type to use a different file type. See below for list of file types. 
--Schedule to run periodically to keep iphone copies up to date. You can use ical or I found a program called "Scenario" that runs scripts when computer is idle so you are not interfered with while working. 
--This script assumes you will not be editing the exported files by comparing modification dates of the outline and exported file. If you do plan on editing these files you need to eliminate the line: "if modification date of (info for eachFile) is greater than the modification date of (info for outputPath) then"
--Notes:
--Keeps any currently open outlines open after exporting so you are not interfered with. However, if there other documents being exported they may flash quickly when the script is run. I have not figured out how to open documents via applescript without them coming to the front intially. 


--Add any file names you do not want to be exported
set ignoreFiles to ""

--Gather all oo3 files in folder
tell application "Finder"
	--USER: Change this path to your outlines folder
	set fl to (files of entire contents of folder POSIX file "/Users/user/my outlines folder/" whose name extension is "oo3") as alias list
end tell

--Make note of any files that are currently open so they are not closed unnecessarily later
tell application "OmniOutliner"
	set openOutlines to name of every document
end tell



repeat with eachFile in fl
	--Set output file path and name
	set theName to name of (info for eachFile)
	--USER: Change this path to your destination folder
	set outputPath to POSIX file ("/Users/user/Google Drive/Outliner iphone copies/" & theName & ".html")
	
	--Logic to export only files that need to be exported
	--ignore any files specified in ignore list above
	--check if output file already exists
	--if it does only export if file has been modified more recently than exported file (note: disable this IF statement if you plan on editing your exported files, this is assuming you'll only be read-only accessing the exported files on your iphone/etc)
	--if exported files doesn't exist then export and create it for the first time
	if ignoreFiles does not contain name of (info for eachFile) then
		tell application "Finder" to if exists outputPath then
			if modification date of (info for eachFile) is greater than the modification date of (info for outputPath) then
				export_file(eachFile, outputPath, openOutlines) of me
			end if
		else
			export_file(eachFile, outputPath, openOutlines) of me
		end if
	end if
	
end repeat

--Subroutine to open, export, and close file
on export_file(eachFile, outputPath, openOutlines)
	tell application "OmniOutliner"
		open eachFile
		tell front document
			--USER: change the text in the quotes to one of the file types listed at the bottom to change export type (current selection is HTML Dynamic)
			export to outputPath as "com.omnigroup.OmniOutliner.HTMLExport.HTMLDynamic"
			--only close file if it wasn't already open before so your open documents are not interfered with
			if openOutlines does not contain name of (info for eachFile) then
				close
			end if
		end tell
	end tell
end export_file


--Output file types:
--org.opml.opml
--com.apple.rtfd
--com.omnigroup.omnioutliner.oo3
--com.microsoft.word.openxml.document
--com.omnigroup.omnioutliner.oo3template
--com.omnigroup.omnioutliner.oo3template-package
--com.omnigroup.omnioutliner.oo3-package
--com.apple.iwork.keynote.key
--com.omnigroup.omnioutliner.plain-text.fixed-width
--public.rtf
--public.plain-text
--com.omnigroup.OmniOutliner.WordExport.MSWordHTML
--com.omnigroup.OmniOutliner.HTMLExport.HTMLDynamic
--com.omnigroup.OmniOutliner.SimpleHTMLExport.HTML