The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Bug in OmniFocus Applescript PBPASTE command (http://forums.omnigroup.com/showthread.php?t=20711)

RobTrew 2011-04-14 11:41 AM

Bug in OmniFocus Applescript PBPASTE command
 
PBCOPY and PBPASTE in the OF applescript library operate on nodes in the Content and Sidebar panels of the GUI.

Pasting a node to a position immediately after its parent should simulate an outlining OUTDENT operation.

This usually works correctly, but a bug is seen if an attempt is made to copy and paste an un-nested action (a top-level child of a project) to a position immediately after its parent project.

The task is correctly promoted to project status,

BUT it is placed in the [B]wrong position[/B] (outside any folders enclosing its parent, rather than as a following sibling of its parent).

An analogous bug (presumably of the same origin) occurs when using the [B]Edit > Outlining > Outdent[/B] command in the OmniFocus menu system. (Kudos to whpalmer4 for spotting this bug, which is presumably located in code which converts tasks to projects, and fails to assign the property which is stored in the cache as [I]ProjectInfo.folder [/I]).

In both cases, outdenting (and the equivalent PBCOPY PBPASTE sequence) works correctly with Folders, Projects, and nested Tasks, and also with Inbox tasks, and Contexts. It only misplaces unnested (top level) project actions and action-groups.

The following is a draft sketch of a replacement for the boxed [B]Outdent[/B] operation. (It moves the misplaced / mispasted object back to the orginally specified target, immediately after the parent project).

For a fully working replacement of outdent, PBCOPY and PBPASTE need to be followed by a deletion of the original node. If you wanted to actually use the code below, you would need to uncomment the two DELETE lines. The code is, however, only intended as an illustrative draft.

[CODE]-- DRAFT REPLACEMENT FOR BUGGY OMNIFOCUS > EDIT > OUTLINING > OUTDENT

tell application id "OFOC"
set oDoc to front document
set oWin to front document window of oDoc
tell oWin
set oPanel to content
set lstNodes to selected trees of oPanel
if (count of lstNodes) < 1 then
set oPanel to sidebar
set lstNodes to selected trees of oPanel
end if
if (count of lstNodes) < 1 then return

repeat with oNode in lstNodes
set oObj to value of oNode
set cClass to class of oObj
if cClass is not item then
if class of container of oObj ≠ document then
set lstAncestors to ancestor trees of oNode

if (count of lstAncestors) > 1 then
pbcopy oNode
set oParent to first item of lstAncestors
pbpaste at (after oParent) -- SPECIFIED LOCATION MISFIRES WITH TASKS CONVERTED TO PROJECTS

tell oObj
if (its class is task) then
set oParentProj to containing project
if (id of parent task) = (id of oParentProj) then
-- TOP LEVEL TASK - WILL BECOME A PROJECT ONCE OUTDENTED
-- AND WILL HAVE BEEN MISPLACED BY A BUG IN PBPASTE
if (folder of oParentProj) is not missing value then
set oProj to value of (last descendant tree of oPanel where class of its value is project)
move oProj to after oParentProj
end if
end if
end if
end tell
tell oPanel to select (first following sibling of oParent)

-- UNCOMMENT THE FOLLOWING LINE IF YOU WISH TO USE THIS IN LIEU OF: OmniFocus > Edit > Outlining > Outdent
-- tell oDoc to delete oObj
end if
else if cClass = inbox task then
pbcopy oNode
-- PASTE AT END OF SIDEBAR LIST OF TOP LEVEL PROJECTS
-- (for compatibility with boxed Outdent,
-- though I prefer it to be at the top for more visibility).
pbpaste at (after trees of tree 2 of sidebar of oWin)

-- UNCOMMENT THE FOLLOWING LINE IF YOU WISH TO USE THIS IN LIEU OF: OmniFocus > Edit > Outlining > Outdent
-- tell oDoc to delete oObj
end if
end if
end repeat
end tell
end tell
[/CODE]


All times are GMT -8. The time now is 11:36 AM.

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