【问题标题】:Script that launches commands on two Terminals在两个终端上启动命令的脚本
【发布时间】:2015-04-05 15:52:41
【问题描述】:

我需要做一个.command 文件脚本/批处理。启动它(双击)它必须对那些东西:

  1. 打开终端窗口 (A)
  2. 启动打开文件所在文件夹的命令(可能是cd "dirname "$0""
  3. 启动命令
  4. 打开终端窗口 (B)
  5. 在第 2 点启动相同的命令
  6. 启动命令

【问题讨论】:

    标签: macos bash terminal


    【解决方案1】:

    鉴于您明确想要创建终端窗口,请考虑使用 AppleScript 创建一个应用程序

    • 打开Script Editor(最高10.9,AppleScript Editor
    • 粘贴下面的代码。
    • 另存为应用程序(通过Save As 对话框中的弹出列表)到所需文件夹。
    # Determine the folder in which this app is located.
    set thisFolder to do shell script "dirname " & quoted form of POSIX path of (path to me)
    
    # Sample commands to execute in the new windows.
    set cmds to {"date", "echo $$"}
    
    tell application "Terminal"
        # Create 2 new windows, change to the
        # this app's folder, and execute the respective command.
        repeat with i from 1 to 2
            do script "cd " & quoted form of thisFolder & "; " & item i of cmds
        end repeat
        # Activate Terminal.app
        activate
    end tell
    

    我建议在*.command 文件上使用应用程序 的原因是后者会在创建所需窗口之前本身在终端窗口中打开,这在视觉上会造成破坏(并且,根据您的 Terminal.app 偏好,可能会打开额外的窗口)。

    或者,您可以将其转化为一种美德,使用*.command 文件自己的窗口作为您的第一个终端窗口,并且只创建 一个 额外的窗口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 2016-11-24
      • 1970-01-01
      相关资源
      最近更新 更多