【发布时间】:2015-04-05 15:52:41
【问题描述】:
我需要做一个.command 文件脚本/批处理。启动它(双击)它必须对那些东西:
- 打开终端窗口 (A)
- 启动打开文件所在文件夹的命令(可能是
cd "dirname "$0"") - 启动命令
- 打开终端窗口 (B)
- 在第 2 点启动相同的命令
- 启动命令
【问题讨论】:
我需要做一个.command 文件脚本/批处理。启动它(双击)它必须对那些东西:
cd "dirname "$0"")【问题讨论】:
鉴于您明确想要创建终端窗口,请考虑使用 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 文件自己的窗口作为您的第一个终端窗口,并且只创建 一个 额外的窗口。
【讨论】: