automator来解决mac terminal终端快速连接

    因最近网络不太稳定,远程连接的ssh服务有时会断掉,于是在网上参考了一些mac terminal终端快速连接的办法,最后选择使用automator来解决。

    下面是antomator 服务的使用方法,并附有一段可运行代码

1、新建服务


automator来解决mac terminal终端快速连接_第1张图片

2、将服务绑定到终端

automator来解决mac terminal终端快速连接_第2张图片

3、一段AppleScript代码

on run {input, parameters}
	tell application "Terminal"
		activate
		do script ""
		set Terminal to front window
		set tab1 to tab 1 of Terminal
		
		# 窗口1中输出
		do script "echo 1" in tab1
                # 或者ssh登录
                # do script "ssh ***" in tab1
                # delay 1    #延迟 1 秒
                # do script "..." 	

 		# 如果标签2不存在则创建
		if not (exists tab 2 of Terminal) then
			tell application "System Events"
				keystroke "t" using command down    #相当于  command+T
			end tell
			set tab2 to tab 2 of Terminal
		end if
		
		# 窗口2中输出
		do script "echo 2" in tab2
                # 或者ssh登录
                # do script "ssh ***" in tab2
         	# delay 1
                # do script "..." 	
 	end tell
	return input
end run

4、进入终端服务修改快捷键

automator来解决mac terminal终端快速连接_第3张图片

automator来解决mac terminal终端快速连接_第4张图片

你可能感兴趣的:(mac)