View Single Post
Quote:
Originally Posted by whpalmer4 View Post
Download OmniOutliner from the product page, fire it up and open the .OPML file you've got. Then select all the rows, copy and try to paste into OmniFocus. You'll get a dialog box that allows you to specify how OO columns map into OF data
Simply dragging one or more OPML files onto a droplet app on your desktop would avoid the need for OmniOutliner and might give an easier workflow (and more control) if it needs to be done at all regularly.

I have placed a simplified version of the droplet which I use at:

http://www.complexpoint.macmate.me/S...L_into_OF.html

It creates a date-stamped OF folder of the imported projects for each OPML file that has been dragged onto the droplet.

(This version just imports the text of each opml node, and any Omni-style _note attribute, but the applescript can easily be adapted to import any other columns/attributes which your opml may have.)

The draft code (to be saved in .app format) looks like this:

Code:
-- DROPLET TO IMPORT OPML FILES INTO OMNIFOCUS

-- Ver 0.4  Now gives warning message if XML Tools osax 
-- from http://www.latenightsw.com/freeware/XMLTools2/index.html
-- has not been copied to ~/Library/ScriptingAdditions


property pstrDialogTitle : "OPML to OmniFocus Ver 0.4"
property pstrImportFolder : "Imported from OPML"
property pEmpty : ""

-- TRY TO READ THE DROPPED FILE(S) AS OPML
-- AND TRANSLATE CONTENTS OF EACH FILE
-- TO A NEW DATE-STAMPED FOLDER OF OF PROJECTS
on open lstfDropped
	set {lstFolders, lngProjects, lngFiles} to {{}, 0, 0}
	repeat with fDropped in lstfDropped
		if IsOPML(fDropped) then
			set strFile to ReadTextFile(fDropped)
			try
				set xmlDoc to parse XML strFile
				set xmlContent to (a reference to XML contents of (last item of XML contents of xmlDoc))
				set lstActivities to XML2List(xmlContent)
				set {lngActs, oFolder} to PlaceInOF(lstActivities)
				set end of lstFolders to oFolder
				set lngProjects to lngProjects + lngActs
				set lngFiles to lngFiles + 1
			on error
				set the clipboard to "http://www.latenightsw.com/freeware/XMLTools2/index.html"
				set strError to "
This script requires installation of Late Night Software's free XML Tools osax

From:

http://www.latenightsw.com/freeware/XMLTools2/index.html

(This URL is now in your clipboard, and can be pasted to a browser)

The version of the XML Tools.osax which matches your operating system should be copied to a folder with the path: 

~/Library/ScriptingAdditions
			"
				display dialog strError buttons {"OK"} with title pstrDialogTitle
				tell application id "com.apple.finder"
					set strAddns to "ScriptingAdditions"
					set fldrLibrary to folder ((path to home folder as string) & "Library") as alias
					if not (exists folder strAddns of fldrLibrary) then
						set fldrAddns to (make new folder at fldrLibrary with properties {name:strAddns})
					else
						set fldrAddns to folder strAddns of fldrLibrary
					end if
					open fldrAddns
					activate front window
				end tell
				return
			end try
		else
			display dialog "Expected file with extension .opml" with title pstrDialogTitle
		end if
	end repeat
	ShowResult(lngProjects, lstFolders, lngFiles)
end open

-- Give feedback to user
on ShowResult(lngProjects, lstFolders, lngFiles)
	if lngProjects > 0 then
		set strMsg to ((lngProjects as text) & " projects placed in OmniFocus" & return & return & 
			"(" & lngFiles as text) & " opml file"
		if lngFiles > 1 then
			set strMsg to strMsg & "s imported)"
		else
			set strMsg to strMsg & " imported)"
		end if
		display dialog strMsg with title pstrDialogTitle
		tell application id "com.omnigroup.OmniFocus"
			tell front document
				set recProps to {selected view mode identifier:"project", focus:lstFolders}
				set oWin to make new document window with properties recProps at front of document windows
			end tell
			activate
		end tell
	else
		display dialog "No projects found in " & strFile with title pstrDialogTitle
	end if
end ShowResult


-- CREATE A FOLDER OF PROJECTS IMPORTED FROM OPML
on PlaceInOF(lstActivities)
	set lngActivities to length of lstActivities
	if lngActivities > 0 then
		tell application id "com.omnigroup.OmniFocus"
			tell front document
				set strName to pstrImportFolder & " " & (current date)
				set oFolder to make new folder with properties {name:strName}
				my FillOFFolder(oFolder, lstActivities)
			end tell
		end tell
		{lngActivities, oFolder}
	else
		{0, missing value}
	end if
	
end PlaceInOF

-- Transfer activities to the specified project (or parent task)
on FillOFFolder(oFolder, lstActivities)
	using terms from application "OmniFocus"
		tell oFolder
			repeat with oAct in lstActivities
				set {strName, lstChiln, strNote} to oAct
				if strNote is missing value then
					set oProj to make new project with properties {name:strName}
				else
					set oProj to make new project with properties {name:strName, note:strNote}
				end if
				if length of lstChiln > 0 then my FillOFProj(oProj, lstChiln)
			end repeat
		end tell
	end using terms from
end FillOFFolder

-- Transfer activities to the specified project (or parent task)
on FillOFProj(oProj, lstActivities)
	using terms from application "OmniFocus"
		tell oProj
			repeat with oAct in lstActivities
				set {strName, lstChiln, strNote} to oAct
				if strNote is missing value then
					set oTask to make new task with properties {name:strName}
				else
					set oTask to make new task with properties {name:strName, note:strNote}
				end if
				if length of lstChiln > 0 then
					my FillOFProj(oTask, lstChiln)
				end if
			end repeat
		end tell
	end using terms from
end FillOFProj

-- READ FROM PARSED XML TO SIMPLE APPLESCRIPT LIST WITH TITLE SUB_LIST AND NOTE
on XML2List(lstContent)
	set lstText to {}
	repeat with xmlNode in lstContent
		try
			-- GET TEXT OF NODE
			set recAttribs to (a reference to XML attributes of xmlNode)
			set lngAttribs to length of recAttribs
			if lngAttribs > 0 then
				set end of lstText to {|text| of recAttribs}
			else
				set end of lstText to {pEmpty}
			end if
			
			-- GET ANY CHILDREN OF NODE
			set refNewNode to (a reference to the last item of lstText)
			set lstChildren to (a reference to XML contents of xmlNode)
			if length of lstChildren > 0 then
				set end of refNewNode to XML2List(lstChildren)
			else
				set end of refNewNode to {}
			end if
			
			-- GET ANY OMNI-STYLE _note OF NODE
			if lngAttribs > 1 then
				set strNote to pEmpty
				set strNote to _note of recAttribs
				if length of strNote > 0 then
					set end of refNewNode to strNote
				else
					set end of refNewNode to pEmpty
				end if
			else
				set end of refNewNode to pEmpty
			end if
		end try
	end repeat
	lstText
end XML2List


on ReadTextFile(fFile)
	open for access fFile
	try
		set strContents to (read fFile)
	on error
		set strContents to ""
	end try
	close access fFile
	return strContents
end ReadTextFile

-- Check that the file has an .opml extension
on IsOPML(fDropped)
	set strFileName to fDropped as string
	set {strDelim, text item delimiters} to {text item delimiters, "."}
	
	set lstParts to text items of strFileName
	set lngParts to length of lstParts
	if lngParts < 2 then
		set blnIsOPML to false
	else
		set strSuffix to (item lngParts of lstParts)
		ignoring case
			set blnIsOPML to (strSuffix is "opml")
		end ignoring
	end if
	set text item delimiters to strDelim
	blnIsOPML
end IsOPML

Last edited by RobTrew; 2012-10-01 at 07:23 AM.. Reason: Ver 0.3 allows for several opml files dropped at once