命令行 查找文件
There are few things more frustrating to any computer user than files opening in an unwanted application. Sure you can use the Open
menu item in the desired application but we all just want to double-click a file and see it open in the application we expect. I recently got to thinking about this dilemma from a command line perspective: how I could find the default application and then change if I wanted to.
除了在不需要的应用程序中打开文件之外,没有什么比让计算机用户感到沮丧的了。 当然,您可以在所需的应用程序中使用“ Open
菜单项,但是我们所有人都只想双击一个文件,然后在我们期望的应用程序中看到它已打开。 我最近从命令行角度考虑了这个难题:如何找到默认应用程序,然后根据需要进行更改。
The first step is installing the duti
utility with HomeBrew:
第一步是使用HomeBrew安装duti
实用程序:
brew install duti
With duti
equipped you can run the following to see the default app and associated ID which opens a given file extension:
配备了duti
您可以运行以下命令查看默认应用程序和关联的ID,这些文件会打开给定的文件扩展名:
# Check to see what app is meant to halde ".js" files
duti -x js
#Visual Studio Code.app
#/Applications/Visual Studio Code.app
#com.microsoft.VSCode
If you don't know the application ID for a given application you'd like to switch a file type to use, you can get it with the following:
如果您不知道给定应用程序的应用程序ID,您想切换使用的文件类型,可以通过以下方法获取:
osascript -e 'id of app "Atom.app"'
# com.github.atom
You can change the default app for a given file extension via:
您可以通过以下方式更改给定文件扩展名的默认应用:
# Use Atom for all ".js" files
duti -s com.github.atom js all
# Open a .js file, watch it open in Atom!
open ~/Projects/debugger.html/src/main.js
There are user interfaces for setting and getting the default app for opening file types but command line provides another type of convenience, if only for the sake of automation. Knowing how to achieve tasks with simple command line executions can make you a more efficient, agile developer!
有用于设置和获取用于打开文件类型的默认应用程序的用户界面,但是命令行提供了另一种便利,即使只是出于自动化的目的。 知道如何通过简单的命令行执行来完成任务,可以使您成为一个更高效,更敏捷的开发人员!
命令行 查找文件