Re-create "Show in Projects" and "Show in Contexts" via Applescript?

There is a bug (already reported) when setting keyboard shortcuts for the “Show in Projects” and “Show in Contexts” menu items. The keyboard shortcut does not work until I open the View menu, displaying the command that I want to invoke.

My attempts to interact with the menus in OmniFocus using anything just shy of GUI scripting have had similarly strange results. So, new plan: I would like to re-create the “Show in Projects” and “Show in Contexts” menu actions via Applescript.

The expected behavior:

One task or project is selected in the current window. I trigger the “Show in Projects” script. The perspective changes to “Projects” and that same task or project is selected.

tell application "OmniFocus"
  tell front document
    tell (first document window whose index is 1)

      set selected_task_id to (id of (selected trees of content)) as string
      set this_task to first flattened task whose id is selected_task_id

    end tell

    set perspective name of document window 1 to "Projects"

    -- We can interact with this_task now, for example by setting flagged to true we can flag it.
    -- However, it OmniFocus does not display or select the flagged task.
    -- So, how to display the task? How to select it?

  end tell
end tell

Note: Perhaps an explanation of tasks/projects vs. trees vs. flattened things would help.

EDIT: Possibly related:

What is «event OTREisal»? As in «event OTREisal» every item of {selectedItem} from the OF1 script reveal.scpt (by Alex Brown, from Curt Clifton’s collection of deprecated OF scripts)?

Edit 2: Some success. The command set (selected trees of content) to this_task has the intended effect (not well tested) but I have no idea what this line actually means. Insights?

Were you able to figure this out?


Ok it seems a possible answer is here - Show task in new window