简体   繁体   English

我怎样才能摆脱这个osascript输出?

[英]How can I get rid of this osascript output?

The following question relates to an answer that was posted on this question : 以下问题与此问题上的答案有关

I like the notion of creating my own function that opens a new terminal, so the script that Craig Walker linked to in that above-referenced question suited my needs. 我喜欢创建我自己的函数来打开一个新终端的概念,所以Craig Walker在上面引用的问题中链接的脚本符合我的需求。 The script, written by Mark Liyanage, is found here. 由Mark Liyanage编写的剧本可在此处找到

That script is this: 那个脚本是这样的:

#!/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 made one change to the script on the linked site; 我对链接网站上的脚本进行了一处更改; I commented out the line that outputs "$COMMAND $EXIT" to eliminate some verbosity. 我注释掉输出“$ COMMAND $ EXIT”的行以消除一些冗长。 However, when I run the script I still get this output 但是,当我运行脚本时,我仍然得到这个输出

tab 1 of window id 2835

just before it opens the new window and executes the command that I pass in. Any ideas why this would be happening? 就在它打开新窗口并执行我传入的命令之前。任何想法为什么会发生这种情况? (I tried moving the redirect of stderr to /dev/null before the call to oascript, but that made no difference.) (我尝试在调用oascript之前将stderr的重定向移动到/ dev / null,但这没有任何区别。)

tab 1 of window 2835 is the AppleScript representation of the object returned by the do script command: it is the tab instance created to execute the command. tab 1 of window 2835do script命令返回的对象的AppleScript表示形式:它是为执行命令而创建的tab实例。 osascript returns the results of the script execution to standard output. osascript将脚本执行的结果返回给标准输出。 Since there is no explicit return in the AppleScript script, the returned value of the whole script is the result of the last-executed statement, normally the do script command. 由于AppleScript脚本中没有显式return ,因此整个脚本的返回值是最后执行的语句的结果,通常是do script命令。 The two easiest fixes are to either redirect stdout of the osascript (and preferably not redirect stderr in case of errors): 最简单的两个修复方法是重定向osascript的stdout(最好不要在发生错误时重定向stderr):

osascript >/dev/null <<EOF

or insert an explicit return (with no value) into the AppleScript. 或者在AppleScript中插入显式return (没有值)。

tell application "Terminal"
    activate
    do script with command "$COMMAND $EXIT"
end tell
return

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM