AppleScript Request: "One Click Search All"

Hi all,

My most used AppleScript in OF1 no longer works. It looks like “Quick Open” would fulfill some of its functions, but this script searches both projects and tasks. Very helpful to call from Quickilver and have it search everything.

I was tinkering with it a bit last night to try and get it working again, but I’d love to have a hand if anyone else wants to pitch in.

Here’s a script I created for use with LaunchBar. If I remember correctly, QuickSilver uses a different handler, but changing the name of the handler shouldn’t be too hard. Please note that the script doesn’t search the inbox, because OmniFocus 2 can’t display the project list and inbox at the same time.

on handle_string(mystring)
	tell application id "com.omnigroup.omnifocus2"
		tell default document
			set myWindow to make new document window
			tell myWindow
				set focus to {}
				set selected sidebar tab to projects tab
				set selected trees of sidebar to sidebar -- deselects everything
				set selected smart group identifier of sidebar to "all-projects" -- deprecated, but works for now
				tell content
					set selected task state filter identifier to "all"
					set selected task duration filter identifier to "any"
					set selected task flagged filter identifier to "all"
				end tell
				set search term to mystring
			end tell
			activate
		end tell
	end tell
end handle_string
1 Like

Thanks a ton!!

I made a few very minor tweaks, and I’m back in business.

on run
    tell application id "com.omnigroup.omnifocus2"
        activate
        set search_term to the text returned of (display dialog "Search:" default answer "Enter search term")
        
        tell default document
            --            set myWindow to make new document window
            set myWindow to first document window
            tell myWindow
                set focus to {}
                set selected sidebar tab to projects tab
                set selected trees of sidebar to sidebar -- deselects everything
                set selected smart group identifier of sidebar to "all-projects" -- deprecated, but works for now
                tell content
                    set selected task state filter identifier to "all"
                    set selected task duration filter identifier to "any"
                    set selected task flagged filter identifier to "all"
                end tell
                set search term to search_term
            end tell
        end tell
    end tell
end run

Cool Script Nathan. And thank you Sven for the help.

What exactly am I seeing in the sidebar when the script runs? is it just all my projects? Should I just disregard?

FWIW, here’s a macro I created in Keyboard Maestro to do the same thing:

Command-2 (to open the Projects perspective)
Command-A (to make sure all projects are selected)
Alt-Command-F (to go to the Search field)

I’ve assigned this macro to F5 - I just hit F5 and I’m immediately in the search field, ready to search everything - as long as it’s assigned to a Project, and is not completed.

I adapt this to a second macro that searches Completed actions, simply by changing the first action in the macro to show me the Completed perspective instead of the Projects perspective.

I changed the script a bit, found it much easier to just make perspectives with the view options I wanted (with the GUI) and then have the script just activate that perspective.

More details: http://n8henrie.com/2014/07/omnifocus-2-applescript-search-all-tasks

The new script: https://gist.github.com/n8henrie/9dd700ab65539921f82d

1 Like

n8henrie that script is excellent and removes my single annoyance in moving from OF1 to OF2.

1 Like

Or, a Keyboard Maestro macro with 2 steps:

Command-2 (to show Projects Perspective)
Alt-Command-F (to put the cursor in the search field).

So now, I just hit the F2 key to trigger this macro and in less than a second, I’m doing an All-Library search.