【问题标题】:exit terminal after execution执行后退出终端
【发布时间】:2014-11-04 13:32:02
【问题描述】:

我有一个运行applescript 的shell 脚本。 applescript 是从终端执行的,我希望该终端在完成后关闭。

在我的 shell 脚本中,我使用这一行执行我的 applescript。它打开一个终端,运行,然后终端就坐在那里,即使苹果脚本已经完成。我有其他终端打开,我一直在使用,所以我不想关闭所有终端,只关闭那个。

 osascript -e 'Tell application "Terminal" to do script "osascript ~/Scripts/reset_simulator.applescript"'

谢谢

【问题讨论】:

    标签: macos shell terminal applescript


    【解决方案1】:

    在您的 shell 脚本中,您执行

    osascript -e 'Tell application "Terminal" to do script "osascript ~/Scripts/reset_simulator.applescript"'
    

    真正打开一个新的 Terminal.app 窗口。

    你有什么特别的理由要打开一个新的终端窗口吗?为什么不运行

    osascript ~/Scripts/reset_simulator.applescript
    

    从您的 shell 脚本和当前窗口中。

    但是如果你想要这样的东西(听起来很奇怪)总是可以使用下一个:

    osascript -e 'Tell application "Terminal" to do script "osascript ~/Scripts/reset_simulator.applescript;exit"'
    #note the "exit" here ---------------------------------------------------------------------------------^^^^^
    

    在 shell 退出时将首选项更改为“关闭窗口”。

    阅读上面的 cmets,听起来我比你想在“背景”中运行一些 applescript。

    所以你可以做下一个:

    a.) 来自你的 shell 脚本

    osascript ~/Scripts/reset_simulator.applescript &
    

    2.) 如果你还想打开另一个终端窗口

    osascript -e 'Tell application "Terminal" to do script "osascript ~/Scripts/reset_simulator.applescript&exit"'
    #note the & here --------------------------------------------------------------------------------------^
    

    【讨论】:

    • 我尝试按照您的建议在不使用终端的情况下运行它,但是这个 shell 脚本是从 TeamCity buildagent 调用的,并且存在某种隐私/安全问题,导致 applescript 无法运行。
    • @deluded12ga - 所以,我添加了另一个选项(见退出)。但是请理解,exit 只有在reset_simulator.applescript 完成时才会执行,正如@nneonneo 在上面的 cmets 中所说的那样。
    • 享受,乐于助人。
    • 很好奇,选项 a 的 & 是什么。)
    • @deluded12ga & 中的shell 它将命令发送到“后台”,因此“前台”脚本的执行立即继续执行下一个命令。通常,当 shell 退出时,后台作业会停止,但您的脚本可能正在处理此类信号。
    【解决方案2】:

    在您的终端设置中,将“Shell->当 shell 退出时”下的设置更改为“如果 shell 干净退出则关闭”。

    【讨论】:

    • 那个不行,试了。终端保持打开状态。
    • 在打开的窗口末尾是否显示“[进程完成]”?
    • 一旦脚本运行,它会说“菜单项退出菜单栏项目的iOS模拟器iOS模拟器应用程序进程iPhone模拟器的菜单栏1的iOS模拟器”
    • 我如何告诉 AppleScript 在完成后退出?
    猜你喜欢
    • 2021-02-21
    • 1970-01-01
    • 2020-01-22
    • 2019-01-25
    • 2011-07-30
    • 2019-03-30
    • 2021-08-17
    • 1970-01-01
    相关资源
    最近更新 更多