我如何摆脱此osascript输出?
题
以下问题与发布的答案有关 这个问题:
我喜欢创建自己打开新终端功能的概念,因此Craig Walker在上述问题中与之相关的脚本适合我的需求。 Mark Liyanage撰写的剧本被发现 这里。
该脚本是这样:
#!/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
我在链接站点上对脚本进行了更改;我评论了输出“ $命令$退出”以消除一些冗长的行。但是,当我运行脚本时,我仍然会得到此输出
tab 1 of window id 2835
在打开新窗口并执行我传递的命令之前。有什么想法会发生这种情况? (我尝试将stderr的重定向转移到呼叫Oascript之前的 /dev /null,但这没什么区别。)
解决方案
tab 1 of window 2835
是由 do script
命令:是 tab
创建的实例是为执行命令。 osascript
将脚本执行的结果返回到标准输出。由于没有明确的 return
在AppleScript脚本中,整个脚本的返回值是最后执行语句的结果,通常是 do script
命令。这两个最简单的修复程序是重定向osascript(最好是 不是 在发生错误时重定向stderr):
osascript >/dev/null <<EOF
或插入显式 return
(没有价值)进入AppleScript。
tell application "Terminal"
activate
do script with command "$COMMAND $EXIT"
end tell
return
不隶属于 StackOverflow