Show task in new window

Can somebody please give me some suggestions on how to show a task in a new window?

This is the task that I have extracted:

Set MyTask to  task id "35678" of document id "adsfadf" of application "OmniFocus"

How do I show it in a new window?

Thanks in advance.

I would like to know this too…

Over a year later. Still no answer. This also parallels a request for option-open to show a task in a new window.

–> When can we expect to be able to do an (option)-control-click in a context menu to open a task in Project view in a new window?

Assuming the answer to at the above is … someday whenever we get around to putting this feature back from OF1 … then …

–> How do we use Applescript to open a selected task in a new window, preferably in Project view?


JJW

This is the closest that I have found, courtesy of Dan Byler:

(*
	# DESCRIPTION #
	
	Inspired by OmniFocus 1 behavior, this script opens the selected task's (or tasks')
	project(s) in a new window so you can jump from a context view into the project view
	without losing place.
	
	# LICENSE #
	
	Copyright © 2015 Dan Byler (contact: dbyler@gmail.com)
	Licensed under MIT License (http://www.opensource.org/licenses/mit-license.php)
	(TL;DR: no warranty, do whatever you want with it.)
	
	# CHANGE HISTORY #
	
	1.0 (2015-04-28)
	-	Initial release

	# INSTALLATION #

	1. Copy script to OmniFocus script folder (OmniFocus -> Help -> Open Scripts Folder)
	2. (Optional) Update to use the icon in this repo
	3. Add script to the OmniFocus toolbar using View -> Customize Toolbar...
		
*)


on main()
	tell application "OmniFocus"
		set myFocus to {}
		-- get selection
		tell content of front document window of front document
			set validSelectedItemsList to value of (selected trees where class of its value is not item and class of its value is not folder)
			set totalItems to count of validSelectedItemsList
			if totalItems is 0 then
				my notifyWithoutGrowl("No valid task(s) selected")
				return
			end if
			repeat with validSelectedItem in validSelectedItemsList
				validSelectedItem
				if (containing project of validSelectedItem) is not missing value then
					set end of myFocus to (containing project of validSelectedItem)
				else if (assigned container of validSelectedItem) is not missing value then
					set end of myFocus to (assigned container of validSelectedItem)
				end if
			end repeat
		end tell
		
		-- no valid projects to focus on
		if length of myFocus is 0 then
			my notifyWithoutGrowl("No projects to focus")
			return
		end if
		
		-- make new window
		tell default document
			make new document window with properties {perspective name:"Projects"}
		end tell
		
		-- set focus
		tell front document window of front document
			set focus to myFocus
		end tell
	end tell
end main

on notifyWithoutGrowl(alertText)
	tell application "OmniFocus" to display dialog alertText with icon 1 buttons {"OK"} default button "OK"
end notifyWithoutGrowl

main()
1 Like

Superb! Thank you.

More to follow once I use this for my own script.


JJW

You can create a new window, then use GetURL to have that window focus on the task in question:

tell application "OmniFocus"
	tell default document
		set MyTask to task id "35678" -- or whatever you've done to get MyTask
		set MyTaskURL to ("omnifocus:///task/" & (id of MyTask))
		tell (make new document window)
			GetURL MyTaskURL
		end tell
	end tell
end tell

Hope this helps!

2 Likes

This script will take a selection and open it in a new project window. The next step might be to modify it to (try to) close the tool bar and the sidebar. I think this can only happen through AppleEvents.

on run
	tell application "OmniFocus"
		
		tell content of front document window of default document to set MyTask to the value of every selected tree
		
		tell default document
			set MyTaskURL to ("omnifocus:///task/" & (id of first item of MyTask))
			tell (make new document window)
				GetURL MyTaskURL
			end tell
			
		end tell
		
	end tell
  end run


JJW

Dan Byler’s script is fantastic, given that double-clicking is not an option. However it does not display completed tasks. Does anyone know how to make it display all the tasks in the project?

The simplest way I can think of to accomplish seeing a task in the context of its project with all completed tasks showing is this:
Set the Projects perspective to show All and save the perspective.
Open the project of the task in question with Cmd-O. Voila: a new window with that project and all tasks showing.

Maybe Dan Byler’s script also relies on the Projects perspective…

1 Like

Cmd-O requires typing the name of the project. Dan Byler’s script is two clicks. Select an action, click on his icon. Not as good as the double-click method in OF1, but better than Cmd-O for me.

However I’m less concerned about this than I was. Now I use Dan Byler’s for actions, and the OF2 focus command for projects. That more or less does what I want.

1 Like

I now understand what you were saying. Setting the Projects perspective (which I never use) to All does affect the result of Dan Byler’s script. Thanks!

1 Like

if I were to try to do this with JXA, would the code be as below?

win.geturl does not work in the code below.

(() => {
    var window = {
        "url": "",
    };
    window["url"] = "omnifocus:///tag/mUexG7H_8aw";

    const omniFocus = Application("OmniFocus");
    omniFocus.includeStandardAdditions = true;

    var win = omniFocus.defaultDocument.documentWindows[0];

    if (window["url"]) {
        console.log("URL is " + window["url"]);
        delay(0.5); // A short delay of 0.5 seconds
        win.geturl(window["url"]);
    }
})();
More details as to why the above code.

I am trying to open some new OF windows, and have that some of those windows point to the a tag. or a project. Pointing to a Perspective works in the code below.

    for (window of target_windows) {
        var of_window = omniFocus.DocumentWindow({
            perspectiveName: window["perspectiveName"],
            "bounds": window["bounds"]
        });
        console.log("Creating window for " + window["perspectiveName"]);
        omniFocus.defaultDocument.documentWindows.push(of_window); // this will create the window
        omniFocus.activate();

although, in my code, I get the reference to the just created window using the line

var win = omniFocus.defaultDocument.documentWindows[0];

not sure if of_window variable can be used.

but all this is a topic for a separate thread.

If you want to show a specific tag in an existing window, this seems to work here:

(() => {
    const 
        // Link to a specific tag object in the database
        tagLink = "omnifocus:///tag/hdugRc85HOF";

    return Application("OmniFocus").geturl(
        tagLink
    )
})();

Let me know if that works for you

1 Like

Thank you. This works!

1 Like