Using the select command in applescript for OmniFocus 1.6 is not easy. For details, see:
http://forums.omnigroup.com/showthread.php?t=11610
OFSelectAny() makes selecting things easy, just pass it a task, project, list of items, IDs of items, etc.
See the next post for testing code which shows how to use OFSelectAny()
http://forums.omnigroup.com/showthread.php?t=11610
OFSelectAny() makes selecting things easy, just pass it a task, project, list of items, IDs of items, etc.
See the next post for testing code which shows how to use OFSelectAny()
Code:
(* OFSelectAny(), code to select items in OmniFocus. By David Amis, version 4/8/2009 Using OFSelectAny() Used to select just about anything in the front window. Currenty only tested in planning mode. Pass any of the following to OFSelectAny(): Sidebar items: sidebar inbox library quick entry tree (not tested) section (not tested) folder project Content items: task inbox task group available task (not tested) remaining task (not tested) by ID, i.e. OFelectAny("pbV93_WpDMx"): project ID (text) task ID (text) List of any of the above Nothing: OFSelectAny({}) Note: Selects parent item in sidebar for a given content item. *) on OFSelectAny(selectItems) -- checks to see if we are processing a list, iterates if necessary local selectItem, extendSelection if class of selectItems is list then if (count of selectItems) is 0 then -- select nothing in the sidebar tell application "OmniFocus" tell default document tell front document window tell sidebar -- if Inbox, Library, Folder, Project, or SAL select {} end tell end tell end tell end tell end if set extendSelection to false repeat with selectItem in selectItems OFSelectOne(selectItem, extendSelection) set extendSelection to true end repeat else OFSelectOne(selectItems, false) end if end OFSelectAny on OFSelectOne(selectItem, extendSelection) local itemClass, textConvertFailed, containingProject tell application "OmniFocus" tell default document set itemClass to class of selectItem if itemClass is rich text then set textConvertFailed to true try set selectItem to task id selectItem set textConvertFailed to false end try if textConvertFailed then try set selectItem to project id selectItem set textConvertFailed to false end try end if if textConvertFailed then error "OFSelectOne:Couldn't find item ID:" & selectItem end if set itemClass to class of selectItem end if if itemClass is task then set containingProject to containing project of selectItem tell front document window tell sidebar select {containingProject} extending extendSelection end tell tell content select {selectItem} extending extendSelection set selected to true -- bug in OmniFocus 1.6: doesn't work end tell end tell else if itemClass is inbox task then tell front document window tell sidebar select inbox extending extendSelection end tell tell content select {selectItem} extending extendSelection set selected to true -- bug in OmniFocus 1.6: doesn't work end tell end tell else --Not needed: if (itemClass is project) or (itemClass is tree) or (itemClass is sidebar tree) then tell front document window tell sidebar select {selectItem} extending extendSelection end tell end tell end if end tell end tell end OFSelectOne