Tiziano Solignani Tiziano Solignani - 1 year ago 99
AppleScript Question

open a Finder's window with applescript a set focus on the spotlight search box

I want to open a Finder's window into a certain folder and then set the focus to the search box, so that I can start typing right away. This is the script I have so far (ok, it open a new finder's tab, not a window, into totalfinder), and I have not been able to find something to get the focus where I would like it to be.

Any hint?

Thank you.

property the_path : "/Users/solignani/Google Drive/c-avv19/doc di lavoro/pratiche/"

set the_folder to (POSIX file the_path) as alias

delay 0.5 -- necessario per evitare che i tasti vengano premuti assieme

tell application "Finder"


if window 1 exists then

tell application "System Events"
keystroke "t" using {command down} -- apre un nuovo pannello
end tell

set target of window 1 to the_folder


open the_folder

end if

end tell

Answer Source

You can add tell application "System Events" to keystroke "f" using {command down} after setting the target of the window. This will select the search bar and enable you to start searching immediately.

If this does not search in the current folder (or target you selected for the window) then go into Finder preferences, click the 'Advanced' tab and change 'When performing a search:' drop-down menu to 'Search the current folder'

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download