Question

Ok, I am trying to make a script where you type something and a new finder window appears with what you typed in it. Similar to spotlight search, but in a script.

set theFind to text returned of (display dialog "What do you want to find?" default answer "" buttons {"Cancel", "Ok"} default button 2)
    tell application "Finder"
        reveal theFind
    end tell
Was it helpful?

Solution

There’s an AppKit method that does exactly what (I think) you’re asking for: -[NSWorkspace showSearchResultsForQueryString:], which means you can use it using AppleScriptObjC. So, in AppleScript Editor, File > New from Template > Cocoa-AppleScript Applet, then:

property NSWorkspace : class "NSWorkspace"
NSWorkspace's sharedWorkspace()'s showSearchResultsForQueryString_(theFind)

Alternatively, you could skip AppleScriptObjC and use the hidden Finder command that that method uses:

tell application "Finder" to «event aevtspot» theFind
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top