I want to open Finder from the terminal with a specific file selected. I know that by using open .
I can open the current directory in Finder, but I also want to select some file in the Finder window.
The basic thing I want to do is run a script that randomly selects a file among many in a folder and for that I need to open a new Finder window with the file selected.
The .
in your open .
command just means path at current location (which would be a folder) so open
decides that the correct application to use is Finder. If you were to do open myTextFile.txt
which is at your current location in the terminal open will decide to use a text editor instead. You can however specify the application to open the file with by using the -a flag so your command would look like this: open -a Finder myTextFile.txt
.
What Faisal suggested will also work, the -R flag is an equivalent to using ⌘↩ (Command Return) in Spotlight.
this and some other nice shell tricks with the open command are described in this post: Shell tricks: the OS X open command
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With