mac命令terminal_如何使用键盘快捷键运行任何Mac Terminal命令

mac命令terminal

mac命令terminal

macbook-keyboard-shorcuts

Are there particular Terminal commands you find yourself running several time a day? Do you wish you could trigger them quickly, with just a keystroke?

您是否发现每天要运行几次特定的终端命令? 您是否希望仅通过按键即可快速触发它们?

As it turns out, you can! We’ve shown you all the Mac keyboard shortcuts you should be using, but this gives you an opportunity to invent your own keyboard shortcut to do just about anything you can imagine with the Terminal. There are two main ways to accomplish this, so let’s get started.

事实证明,可以! 我们已经向您显示了您应该使用的所有Mac键盘快捷键,但这为您提供了一个发明自己的键盘快捷键的机会,以使您几乎可以使用终端进行任何操作。 有两种主要方法可以完成此操作,所以让我们开始吧。

简单方法:iCanHazShortcut (The Easy Way: iCanHazShortcut)

The easiest way to add custom keyboard shortcuts for specific commands is to download iCanHazShortcut, a free Mac application with a terrible name. Installing couldn’t be simpler: just drag the icon to your Applications folder.

为特定命令添加自定义键盘快捷键的最简单方法是下载iCanHazShortcut ,这是一个名称可怕的免费Mac应用程序。 安装再简单不过了:只需将图标拖到“应用程序”文件夹中即可。

icanhazshortcut-install

Then fire up the application. You’ll find it in the menu bar.

然后启动该应用程序。 您会在菜单栏中找到它。

icanhazshortcut-running

Click “Shortcuts” to bring up a list of current shortcuts.

单击“快捷方式”以显示当前快捷方式的列表。

icanhazshortcuts-window

Looks like we don’t have any shortcuts defined right now. To change this, click the green arrow at bottom-right. This will bring up a two fields: one for the keyboard shortcut, another for the command you’d like to trigger.

看来我们目前尚未定义任何快捷方式。 要更改此设置,请单击右下角的绿色箭头。 这将显示两个字段:一个用于键盘快捷键,另一个用于您要触发的命令。

icanhazshortcut-shortcut

Click the first field, then hit whatever keyboard shortcut you’d like to use. Next, click the second field and enter whatever command you’d like to trigger. For our example, we’re going to use date "+The time is %H:%M" | say which makes our Mac say the current time out loud.

点击第一个字段,然后点击您要使用的任何键盘快捷键。 接下来,单击第二个字段,然后输入要触发的任何命令。 对于我们的示例,我们将使用date "+The time is %H:%M" | say date "+The time is %H:%M" | say ,这使我们的Mac大声说出当前时间。

Click the green checkmark at bottom-right, and your done! Your keyboard shortcut will now run your command at will.

单击右下角的绿色复选标记,然后完成! 现在,您的键盘快捷键将随意运行您的命令。

icanhazshortcut-preferences

Note that you can configure a few more things, if you like. The icon menu bar icon can be disabled, allowing you to run this application in the background. You can also set the application to run when you start up your computer.

请注意,您可以根据需要配置其他一些内容。 可以禁用图标菜单栏图标,使您可以在后台运行此应用程序。 您还可以将应用程序设置为在启动计算机时运行。

(稍微)困难但内置的方式:自动器 (The (Slightly) Harder, But Built-In Way: Automator)

If you’d rather not use a third party application to trigger Terminal commands, there’s another method, which works because macOS lets you set custom keyboard shortcuts for everything. To get started we’re going to launch Automator, which you’ll find in your Applications folder. We’re going to create a new Service for your Mac.

如果您不希望使用第三方应用程序来触发终端命令,那么还有另一种方法可以使用,因为macOS允许您为所有内容设置自定义键盘快捷键。 首先,我们将启动Automator ,您可以在Applications文件夹中找到它。 我们将为您的Mac创建一个新的服务。

automator-create-service

In the Actions section, click the “Utilities” sub-section, then drag “Run Shell Script” over to your workflow.

在“操作”部分中,单击“实用程序”子部分,然后将“运行Shell脚本”拖到您的工作流程中。

automator-shell-script

Next, paste your command.

接下来,粘贴您的命令。

automator-run-script-time

Again I’ve used date "+The time is %H:%M" | say, which will read the current time out loud, but you can use whatever command you like. Save your workflow with a name you’ll recognize, and we’re done with Automator.

我再次使用date "+The time is %H:%M" | say date "+The time is %H:%M" | say ,它将大声读出当前时间,但是您可以使用任何喜欢的命令。 使用您可以识别的名称保存您的工作流,而Automator已经完成。

Next, head to System Preferences > Keyboard > Shortcuts. In the left panel click “Services,” and scroll down until you see the service you just created—it should be under the “General” section.

接下来,转到“系统偏好设置”>“键盘”>“快捷方式”。 在左侧面板中,单击“服务”,然后向下滚动,直到看到您刚刚创建的服务,该服务应位于“常规”部分下。

automator-say-time-keyboard-shortcut

After setting this, you can trigger your service using whatever shortcut you defined. And because this is all native to the operating system itself, there’s no program you need to leave running in the background.

设置此选项后,您可以使用定义的任何快捷方式触发服务。 而且由于这都是操作系统本身的本机,因此无需在后台运行程序。

翻译自: https://www.howtogeek.com/286332/how-to-run-any-mac-terminal-command-with-a-keyboard-shortcut/

mac命令terminal

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值