The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus 1 for Mac (http://forums.omnigroup.com/forumdisplay.php?f=38)
-   -   omnifocus: links (http://forums.omnigroup.com/showthread.php?t=16130)

gshenaut 2010-05-06 09:57 AM

omnifocus: links
 
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.)

Thanks,
Greg Shenaut

gshenaut 2010-05-06 11:26 AM

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.

Craig 2010-05-06 12:45 PM

Something on this thread might be of help to you:
[url]http://forums.omnigroup.com/showthread.php?t=7998[/url]

gshenaut 2010-05-06 03:45 PM

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
[CODE]set MyProjectArray to complete ProjectString as project maximum matches 1
set MyProjectID to id of first item of MyProjectArray[/CODE]
be modified to use an exact string match instead of a completion to find a project's ID?

Brooks 2010-05-07 04:13 AM

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.

Greg Jones 2010-05-07 05:18 AM

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.

gshenaut 2010-05-07 06:01 AM

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".

Cheers,
Greg

RobTrew 2010-05-07 08:14 AM

[QUOTE=gshenaut;76866]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.[/QUOTE]

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 [B]maximum matches[/B] 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.

[CODE]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 !
else
-- sorry ! no matches at all !
end if
end tell
end tell
[/CODE]

gshenaut 2010-05-07 08:41 AM

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.

RobTrew 2010-05-07 11:25 AM

[QUOTE=gshenaut;76893]Is there some way to not include projects with names like "Foobar" for input "Foo" using "complete"?[/QUOTE]

You just need to iterate through the list of matches, and pull out the exact ones.

e.g. something like:

[CODE]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
else
-- 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
lstExact
end ExactMatchProjects

[/CODE]


All times are GMT -8. The time now is 12:00 PM.

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