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

StackOverflow https://stackoverflow.com/questions/16665806

  •  30-05-2022
  •  | 
  •  

質問

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"

activate

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

else

    open the_folder

end if

end tell
役に立ちましたか?

解決

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

他のヒント

Instead of Ctrl-F, try Ctrl-F5. This should get what you need.

On OS X 10.11.5, System Preference > Keyboard > Shortcut keys > Keyboard. You will find Ctrl-F5 is to "move to window toolbar", but on Finder, this will set the focus to the search field without "entering into a search modality".

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top