How to get focus on quick entry when using applescript -> quick entry

I’m using an applescript to create tasks from email from my command-line-based mail client on OS X. Nothing fancy, it’s a script based on of the scripts that was shared on this forum. Works great, did work even better in the past.

The problem is: whenever I have created a new entry, the focus doesn’t move to the Quick Entry-window. In the past it did. Then I could create a new task and hit the tab to switch between the fields to, for example, specify a due date. Now the focus is not on the Quick Entry-window and hitting tab doesn’t do anything at all.

How to get the focus to that window?

And yes, I’ve Google’d and searched this forum, but a search term like “focus” doesn’t really work. :)

If I understand you correctly, you’re looking for “bring window to the front.” Or potentially open/activate an application. Which makes me think of this:

tell application "Terminal"
    reopen
    activate
end tell

Source:

That does not seem to work, unfortunately. The problem is not that the quick entry window is not in the front. When invoking the script it does get raised and is on top of all other windows. The only thing that is not, is that it does not seem to have the focus. In other words: when typing “tab” to switch input fields, it doesn’t do anything at all.

So, what I am trying to get working is running the script (works), than have the quick entry dialog opened (works), then hit tab one or a couple times to get to the right field like the due date (not working), then change the contents of that field and only then hit enter to actually commit to Omnifocus.

Oh, I think I follow. Try this:

tell application "OmniFocus"
	tell quick entry
		set theTask to make new inbox task
		open
	end tell
end tell

tell application "System Events"
	key code 125
	key code 48
end tell

First experiment with this addition: success. Thanks a lot for the suggestion! Will test this next few days some more before I declare this a victory. :)

1 Like