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 > OmniFocus > OmniFocus 1 for Mac
FAQ Members List Calendar Search Today's Posts Mark Forums Read

omnifocus: links Thread Tools Search this Thread Display Modes
If I'm in a project folder on my Mac, working on the project, I'd like to be able to quickly open the corresponding OmniFocus project. It turns out that there is a nifty feature in OmniFocus whereby if you control-click on the name of a project, one of the options is "copy as link". The result is a URL of the form "omnifocus:///task/jexW10LHv6C". From outside OmniFocus, even if it is not running, opening that URL will open an OmniFocus window containing the project, which is very nice. However, what I *really* want is to go from the *name* of the project to the OmniFocus project window. Probably, there is some way to do that using AppleScript, but my AppleScript ability is limited to adapting other peoples' solutions. How would one do the equivalent of the Terminal command "open 'omnifocus:///task/jexW10LHv6C'" in AppleScript, but instead of the "jexW10LHv6C" gobbedly-gook, with a project name, like "Friday Report"? (Actually, it says "task" in the URL, so apparently this method could be used for both tasks and projects, and maybe other things as well.)

Greg Shenaut
Additional information on this, I found in the xml-format OmniFocus database an entry for a task with the same ID used in the URL, containing a "project" entry and a "name" entry that gave the name of the project. So, I could hack my way to a solution via the raw database without using AppleScript, I suppose.
Something on this thread might be of help to you:
Yes, that's in the right direction, but I don't want to "complete" a project name, I want to find the id of a specific project from its name. The completion method is inherently ambiguous. I wrote a shell script kludge based on the xml file but would rather use something more standard.

How can these lines
set MyProjectArray to complete ProjectString as project maximum matches 1
set MyProjectID to id of first item of MyProjectArray
be modified to use an exact string match instead of a completion to find a project's ID?
I might be missing something from your description, but would this work:

1) Use Copy Link on a OmniFocus project
2) Paste the OmniFocus link into a TextEdit document
3) Drag the link from the TextEdit document into your project folder in the finder.
4) Change file name from task/jexW10LHv6C to "Friday Report"

I'm sure one use Automator to construct a script which would automate much of this process.
Taking Brooks' idea one step further, one could bypass TexEdit and instead paste the link in the notes field of the project, then proceed with Step #3.
Thanks for the ideas, but let me be a little more specific about what I'm trying to do. Finder has a toolbar where you can drag applications to be executed as plugins. I have projects organized in folders where the convention is that the name of the folder is the name of the project. I have various key files inside the project folder that also use that name. For example, for a project Foobar, I have a folder Foobar, and inside that folder I have Foobar.scriv, Foobar.graffle, and Foobar.xcodeproj (just to use some random examples). I also have an OmniFocus project called Foobar. What I'm doing is making a Finder toolbar plugin such that when I enter the folder Foobar in Finder and click on the plugin in the toolbar, it automagically opens all of the key elements of the project in their default applications (Scrivener, Omnigraffle, and XCode in this case), and also opens the corresponding OmniFocus project, if any, by itself in a window. I actually have this working, but at the moment, I'm using a crude shell script to extract the id of the project whose name is the same as the frontmost Finder folder from the XML file, and then using "open omnifocus:///task/<theID>" to get the project window. I'd rather use something less kludgy and more robust for this.

I don't want to have to go through the step of manually saving the omnifocus link somewhere every project folder, I want to use my simple naming convention instead. However, the example scripts using the "complete" function won't work properly, because I might well have other projects called "Foo" and "Foobar Reloaded".

Originally Posted by gshenaut View Post
Yes, that's in the right direction, but I don't want to "complete" a project name, I want to find the id of a specific project from its name. The completion method is inherently ambiguous.
On the complete method ...

The complete method has to be "inherently ambiguous" simply because the data is inherently ambiguous. Nothing prevents 2 projects (or 10 projects for that matter) from having identical names, so there can, alas, be no simple mapping of a name string onto a unique id.

You just have to remove the maximum matches parameter, see how many matches you have got in your data, and handle the harvest iteratively in the way that makes sense for your application.

tell application "OmniFocus"
	tell front document
		set lstMatches to complete strPattern as project
		set lngMatches to length of lstMatches
		if (lngMatches) > 1 then
			-- deal with the multiple matches ...
			repeat with recMatch in lstMatches
				set {_, lngScore, strID, strName} to recMatch as list
				-- handle each match here ...
			end repeat
		else if lngMatches > 0 then
			-- good ! you have a unique match !
			-- sorry ! no matches at all !
		end if
	end tell
end tell
That's interesting. I suppose I simply should not open an OmniFocus window at all when there is more than one project for a given name, or maybe even pop up an error message, since under my naming convention, that would be a user error. Another possibility might be to open *all* projects with that name in separate windows or all in one window (if that's even possible).

But that takes me back to "inherent ambiguity": Is there some way to not include projects with names like "Foobar" for input "Foo" using "complete"? As I understand it, invoking *complete "Foo"* will return all projects whose name contains "Foo" as a substring, including "Foobar", but it would *not* be erroneous to have two different projects named like that.
Originally Posted by gshenaut View Post
Is there some way to not include projects with names like "Foobar" for input "Foo" using "complete"?
You just need to iterate through the list of matches, and pull out the exact ones.

e.g. something like:

tell application "OmniFocus"
	set oDoc to front document
	set strName to "xyz" as string
	set lstProjects to my ExactMatchProjects(oDoc, strName)
end tell

on ExactMatchProjects(oDoc, strName)
	using terms from application "OmniFocus"
		tell oDoc
			set lstExact to {}
			set lstMatches to complete strName as project
			if (count of lstMatches) > 0 then
				repeat with recMatch in lstMatches
					set {_, _, strID, strMatch} to recMatch as list
					if strMatch is strName then
						set end of lstExact to project id strID
						-- sorted by score, so there will be no more
						-- exact matches
						exit repeat
					end if
				end repeat
			end if
		end tell
	end using terms from
end ExactMatchProjects

Last edited by RobTrew; 2010-05-07 at 11:55 PM..

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open OmniFocus links in the same window? JustinLuey OmniFocus 1 for Mac 0 2012-06-25 05:20 PM
Links to OmniFocus from another app plopp OmniFocus for iPhone 1 2009-10-15 04:35 PM
Ad hoc links OmniFocus <--> Devonthink RobTrew OmniFocus 1 for Mac 4 2009-06-23 02:22 PM
'Clickable' URLs or web-links in OmniFocus Bruce L OmniFocus 1 for Mac 5 2007-12-16 06:56 PM
OmniFocus-Mail Links curt.clifton OmniFocus 1 for Mac 60 2007-06-20 04:32 PM

All times are GMT -8. The time now is 12:55 AM.

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