macOS set shortcut key to start terminal

macOS set shortcut key to start terminal

In the Linux system, I am used to calling out the terminal anywhere to do some simple work, such as downloading something with aria2c.

Switching to macOS is very troublesome. The terminal that comes with the macOS system does not support setting shortcut keys to quickly open a command line window. But we can achieve this operation through "automatic operation" + "Apple Script".

automatic operation

Open Automator ( automator.app) -> New 服务.

Add a step inside 运行 AppleScript:

Screenshot of automatic operation settings

Fill in the Apple Script content:

on run {input, parameters}
	tell application "Terminal"
		set origSettings to default settings
		set default settings to settings set "mine quick"
		do script ""
		activate
		set default settings to origSettings
	end tell
	
	return input
end run

What this code does is:

  • Let the terminal app set the default description file
  • Create a new terminal window with the set description file
  • Finally reset the default description file to the previous default

Don't forget to save this automatic operation, give it a name, such as New Terminal Window.

If you don't need to open a terminal window to specify a specific description file, setjust delete those three lines :

specific profile

The description file is the style, and the configuration of what shell to use: (in the preferences of the terminal)

Profiles Settings Page in Terminal Preferences

The default description file of my terminal is "Pro", which is usually used for work. Yours is a pure black, opaque one, using bash, very classic:

Pro Profile Effects

I also customized a description file named "mine quick". The main difference between this description file and Pro is that it provides a translucent frosted glass effect and uses zsh. This description file is more modern and more in line with the current style of macOS UI:

mine quick profile effect

(Another point: this mine quick will increase the transparency when it is inactive, that is, after the mouse clicks on other windows, so that it will not block the content of the lower window. In short, this mine quick is more convenient for quick auxiliary work)

I want to get a Pro-style one by manually opening the window from the Terminal app icon when doing serious work. The terminal window opened by the shortcut key is only used quickly and casually, and the auxiliary operation uses the mine quick description file.

So there is the operation of setting the description file.

Set global shortcut keys

Settings -> Keyboard -> Shortcuts -> Services:

Set shortcut key screenshot

reference

  • https://cloud.tencent.com/developer/ask/106143
  • https://apple.stackexchange.com/questions/122875/opening-new-terminal-app-window-tab-with-a-certain-profile-from-command-line-or
  • https://www.zhihu.com/question/20692634

Guess you like

Origin blog.csdn.net/u012419550/article/details/119821012