2011-06-26 88 views
0

哦,我的Mac,无论何时我启动终端,我想运行几个命令,打开另一个选项卡,cd到某个目录中,在本地启动一个服务器,然后SSH到远程服务器。mac自动终端命令?

我该如何自动执行此操作?

谢谢

回答

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 
0

看一看Terminitor。它的重点是设置每个项目的终端,但配置可以保存在一个文件中并随意运行。

如果不能证明是有益的,一为AppleScript的由@netrom

0

提到的命令添加到您的〜/ .bashrc文件,并确保它每次都拼命地跑启动终端:

首选项> Shell>启动>标记:运行命令并键入:source〜/ bashrc