Macos mac自动终端命令?

Macos mac自动终端命令?,macos,terminal,Macos,Terminal,噢,我的mac,每当我启动终端时,我都想运行一些命令,打开另一个选项卡,将cd放入某个目录,在本地启动一个服务器,并将ssh插入远程服务器 如何自动执行此操作 谢谢您可以编写一个shell脚本来完成所有这些。如果您不想在登录SSH服务器时手动输入密码,那么您可以将密钥作为授权密钥放在远程服务器上,而不需要密码(当然,如果配置正确) 演示如何使用AppleScript打开终端、设置焦点、打开4个选项卡等。您可以根据自己的需要对其进行修改 以下AppleScript激活终端,创建一个新选项卡,并在第

噢,我的mac,每当我启动终端时,我都想运行一些命令,打开另一个选项卡,将cd放入某个目录,在本地启动一个服务器,并将ssh插入远程服务器

如何自动执行此操作


谢谢

您可以编写一个shell脚本来完成所有这些。如果您不想在登录SSH服务器时手动输入密码,那么您可以将密钥作为授权密钥放在远程服务器上,而不需要密码(当然,如果配置正确)

演示如何使用AppleScript打开终端、设置焦点、打开4个选项卡等。您可以根据自己的需要对其进行修改

以下AppleScript激活终端,创建一个新选项卡,并在第二个选项卡中执行“your_命令”(执行所需操作的脚本):

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
在菜单上单击(mList)
本地应用程序名、topMenu、r
--验证我们的输入
如果mList的长度小于3,则出现错误“菜单列表不够长”
--为了以后的清晰和简洁,设置这些变量
将{appName,topMenu}设置为(mList的第1项到第2项)
将r设置为(mList的项目3至(mList的长度)
--这条过长的行调用menu_recurse函数
--两个参数:r和对顶级菜单的引用
告诉应用程序“系统事件”到我的菜单\u单击\u递归(r,((进程appName)'s(菜单栏1)'s(菜单栏项topMenu)'s(菜单topMenu)))
结束菜单\u单击
在菜单上单击递归(mList,parentObject)
局部f,r
--`f`=第一项,`r`=其余项
将f设置为mList的项目1
如果mList的长度>1,则将r设置为(mList的项目2到(mList的长度))
--或者实际单击菜单项,或者再次递归
告诉应用程序“系统事件”
如果mList的长度为1,则
单击父对象的菜单项f
其他的
我的菜单\u单击\u递归(r,(父对象的(菜单项f))的(菜单项f)))
如果结束
结束语
结束菜单\u单击\u递归
告诉应用程序“终端”
激活
我的菜单点击({“终端”、“外壳”、“新标签”、“专业”})
将窗口id设置为最前面为true的第一个窗口的id
在应用程序“终端”的窗口id窗口id选项卡2中编写脚本“您的命令”
结束语
看一看。它的重点是为每个项目设置终端,但配置可以保存在单个文件中,并可以随意运行


如果这证明没有帮助,@netrom提到的Applescript的+1将命令添加到~/.bashrc文件中,并确保每次启动终端时都运行该命令:

首选项>Shell>启动>标记:Run命令和类型:source~/bashrc