mac命令terminal_如何使用鍵盤快捷鍵執行任何Mac Terminal命令
mac命令terminal
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
事實證明,可以! 我們已經向您顯示了您應該使用的所有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.
為特定命令新增自定義鍵盤快捷鍵的最簡單方法是
Then fire up the application. You’ll find it in the menu bar.
然後啟動該應用程式。 您會在選單欄中找到它。
Click “Shortcuts” to bring up a list of current shortcuts.
單擊“快捷方式”以顯示當前快捷方式的列表。
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.
看來我們目前尚未定義任何快捷方式。 要更改此設定,請單擊右下角的綠色箭頭。 這將顯示兩個欄位:一個用於鍵盤快捷鍵,另一個用於您要觸發的命令。
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.
單擊右下角的綠色複選標記,然後完成! 現在,您的鍵盤快捷鍵將隨意執行您的命令。
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建立一個新的服務。
In the Actions section, click the “Utilities” sub-section, then drag “Run Shell Script” over to your workflow.
在“操作”部分中,單擊“實用程式”子部分,然後將“執行Shell指令碼”拖到您的工作流程中。
Next, paste your command.
接下來,貼上您的命令。
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.
接下來,轉到“系統偏好設定”>“鍵盤”>“快捷方式”。 在左側面板中,單擊“服務”,然後向下滾動,直到看到您剛剛建立的服務,該服務應位於“常規”部分下。
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