命令行 查找文件_在命令行中查找和更改文件类型的默认应用

命令行 查找文件

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!

有用于设置和获取用于打开文件类型的默认应用程序的用户界面,但是命令行提供了另一种便利,即使只是出于自动化的目的。 知道如何通过简单的命令行执行来完成任务,可以使您成为一个更高效,更敏捷的开发人员!

翻译自: https://davidwalsh.name/default-app-file-type

命令行 查找文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值