从终端打开Finder,并选择文件 [英] Opening Finder from terminal with file selected

查看:120
本文介绍了从终端打开Finder,并选择文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从终端打开Finder,并选择一个特定的文件.我知道使用open .可以在Finder中打开当前目录,但是我也想在Finder窗口中选择一些文件.

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.

我要做的基本操作是运行一个脚本,该脚本在一个文件夹中的许多文件中随机选择一个文件,为此,我需要打开一个新的Finder窗口,并选择文件.

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.

推荐答案

open .命令中的.只是表示当前位置(可能是文件夹)的路径,因此open决定要使用的正确应用程序使用的是Finder.如果要执行open myTextFile.txt,它位于终端的当前位置,则打开时将决定使用文本编辑器.但是,您可以使用-a标志指定用于打开文件的应用程序,这样您的命令应如下所示:open -a Finder myTextFile.txt.

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.

Faisal建议的内容也可以使用,-R标志等效于在Spotlight中使用⌘↩(命令返回).

What Faisal suggested will also work, the -R flag is an equivalent to using ⌘↩ (Command Return) in Spotlight.

此文章中介绍了open命令的此技巧以及其他一些不错的shell技巧:

this and some other nice shell tricks with the open command are described in this post: Shell tricks: the OS X open command

这篇关于从终端打开Finder,并选择文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆