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
Était-ce utile?

La 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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top