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
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
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…
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.
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!
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];
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
)
})();