1

I want to know how to modify the following Shell Script to achieve what I want.

The script is used in MacVim. To explain its purpose, suppose you open a .tex file in gVim. If you run the script within gVim, a new Terminal window is opened, and LaTeXmk (a programme to automatically compile .tex files) starts running and compiling a .tex file opened in gVim.

In this process, two Terminal windows are opened. One for a starting window (just $ prompt), and the other showing that LaTeXmk is running. Since the first window is not needed once LaTeXmk runs, I want to automatically close it after the script is invoked.

Can anyone tell me how to modify the script to automatically close the first Terminal window?

#!/bin/sh 
# 
# Open a new Mac OS X terminal window with the command given 
# as argument. 
# 
# - If there are no arguments, the new terminal window will 
#   be opened in the current directory, i.e. as if the command 
#   would be "cd `pwd`". 
# - If the first argument is a directory, the new terminal will 
#   "cd" into that directory before executing the remaining 
#   arguments as command. 
# - If there are arguments and the first one is not a directory, 
#   the new window will be opened in the current directory and 
#   then the arguments will be executed as command. 
# - The optional, leading "-x" flag will cause the new terminal 
#   to be closed immediately after the executed command finishes. 
# 
# Written by Marc Liyanage <http://www.entropy.ch> 
# 
# Version 1.0 
# 

if [ "x-x" = x"$1" ]; then 
     EXIT="; exit"; shift; 
fi 

if [[ -d "$1" ]]; then 
     WD=`cd "$1"; pwd`; shift; 
else 
     WD="'`pwd`'"; 
fi 

COMMAND="cd $WD; $@" 
echo "$COMMAND $EXIT" 

osascript 2>/dev/null <<EOF 
     tell application "Terminal" 
         activate 
         do script with command "$COMMAND $EXIT" 
     end tell 
EOF 

I found the script at

http://vim.1045645.n5.nabble.com/latexmk-from-macvim-tt1212353.html

and asked a similar question in the thread, but no reply has been given so far. I found the script extremely useful and think that it may be for other LaTeX users as well.

4

1 回答 1

2

该选项不在 shell 中 - 它在终端首选项中。打开首选项 -> 设置 -> 外壳 -> 当外壳退出时:设置此项以关闭窗口。

于 2013-05-23T11:09:09.600 回答