View Single Post
Sorry about that Greg, not sure why. Here's the script:

Code:
on run
    tell application "OmniFocus"
        tell front document
            tell document window 1
                set selectedTrees to selected trees of content
                
                set selectedTrees to selected trees of content
                if (count of selectedTrees) is less than 2 then
                    set selectedTrees to selected trees of sidebar
                end if
                
                set treeCount to count of selectedTrees
                
                if not treeCount ≥ 2 then
                    display dialog "more than two projects must be selected in order to set a dependency"
                    --should also check to make sure they're projects and not tasks 
                else
                    
                    -- obtain the project which is the "active" project, the one on which the others are waiting
                    --   build the list of names
                    set treeNames to {}
                    repeat with aTree in selectedTrees
                        set end of treeNames to name of aTree
                    end repeat
                    
                    --   obtain selection from user
                    set nameOfActiveTree to {choose from list treeNames with prompt "Choose the project that should remain active (all others will be placed on hold):"}
                    
                    --   now loop through the selected projects and grab the one the user specified, by name
                    set activeTree to missing value
                    repeat with aTree in selectedTrees
                        if (name of aTree as string) is equal to (nameOfActiveTree as string) then
                            set activeTree to aTree
                        end if
                    end repeat
                    set activeProject to the value of activeTree
                    
                    -- now do the stuff
                    repeat with aTree in selectedTrees
                        set aProject to the value of aTree
                        if aProject = activeProject then
                            
                        else
                            -- add task with link to the active project, and set the status to on hold
                            tell activeProject
                                set newTask to make new task with properties {name:"activate project: " & name of aProject, note:"omnifocus:///task/" & id of aProject & linefeed}
                            end tell
                            set status of aProject to on hold
                            
                            -- add task with link to the blocked project
                            tell aProject
                                set newTask to make new task at beginning with properties {name:"this project on hold pending completion of: " & name of activeProject, note:"omnifocus:///task/" & id of activeProject & linefeed}
                            end tell
                        end if
                    end repeat
                end if
            end tell
        end tell
    end tell
end run

-- TODO:
-- could create an accompanying script that locates the linked project in a task's notes, activates it, and then toggles the status of the task

Watch out for an annoyance with the selection - if there are non-projects (i.e. tasks) selected in the right pane, the script won't work. I haven't tested what it does in this scenario, but I should probably update the script to handle it.