哦,我的mac,每当我启动终端时,我想运行一些命令,打开另一个选项卡,cd到某个目录,在我的本地启动服务器,然后ssh到远程服务器。
我该如何自动执行此操作?
由于
答案 0 :(得分:1)
您可以编写一个执行所有操作的shell脚本。如果您不想在登录SSH服务器时手动输入密码,那么您可以将密钥作为不需要密码的授权密钥放在远程服务器上(如果配置正确的话)。
This page展示了如何使用AppleScript打开终端,为其提供焦点,打开4个标签等。您可以根据自己的需要对其进行修改。
以下AppleScript激活终端,创建新标签并执行" your_command" (在第二个标签中执行您想要的脚本):
on menu_click(mList)
local appName, topMenu, r
-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"
-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)
-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s (menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click
on menu_click_recurse(mList, parentObject)
local f, r
-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
click parentObject's menu item f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse
tell application "Terminal"
activate
my menu_click({"Terminal", "Shell", "New Tab", "Pro"})
set window_id to id of first window whose frontmost is true
do script "your_command" in tab 2 of window id window_id of application "Terminal"
end tell
答案 1 :(得分:0)
看看Terminitor。它的重点是设置每个项目的终端,但配置可以保存在一个文件中并随意运行。
如果这不能证明有用,那么@netrom
提到的Applescript为+1答案 2 :(得分:0)
将命令添加到〜/ .bashrc文件中,并确保每次启动终端时都会运行它:
偏好设置&gt;壳牌&gt;启动&gt;标记:运行命令并输入:source~ / bashrc