“退出”的替代方案命令

发布于 2024-11-28 07:15:19 字数 157 浏览 1 评论 0原文

我知道问题标题看起来很奇怪,所以我会尝试更好地解释它:我知道您可以通过这样做使应用程序退出:

tell application "whatever" to quit

我想知道是否有任何替代方法可以这样做。

提前致谢。

I know the question title looks weird so I'll try to explain it better: I know you can make applications quit by doing this:

tell application "whatever" to quit

I want to know if there are any alternatives to doing this.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

灼痛 2024-12-05 07:15:19

您可以像这样使用GUI Scripting...

tell application "System Events" to tell process "whatever" to keystroke "q" using {command down}

You could use GUI Scripting like this...

tell application "System Events" to tell process "whatever" to keystroke "q" using {command down}
怀念你的温柔 2024-12-05 07:15:19

告诉应用程序“无论如何”退出方法的问题是,您只能定位在编译脚本时安装在计算机上的应用程序。这是一个 AppleScript,它确定所有正在运行的应用程序进程的名称,然后通过向其发送 quit 命令来退出每个进程。

property pExcludeApps : {"Finder", name of current application}

tell application "System Events"
    set theAppsToQuit to name of every process where background only = false
end tell

repeat with theApp in theAppsToQuit
    if pExcludeApps does not contain contents of theApp then
        tell application (contents of theApp)
            quit saving yes
        end tell
    end if
end repeat

The problem with the tell application "whatever" to quit approach is that you can only target applications that are installed on your machine upon compilation of the script. Here's an AppleScript that determines the names of all running application processes and then quits each one by sending it the quit command.

property pExcludeApps : {"Finder", name of current application}

tell application "System Events"
    set theAppsToQuit to name of every process where background only = false
end tell

repeat with theApp in theAppsToQuit
    if pExcludeApps does not contain contents of theApp then
        tell application (contents of theApp)
            quit saving yes
        end tell
    end if
end repeat
尸血腥色 2024-12-05 07:15:19
delay 5
tell application (path to frontmost application as text) to quit saving no

delay 5
tell application "System Events" to set pid to unix id of (process 1 where frontmost is true)
do shell script "kill " & pid

tell application "TextEdit" to close windows
tell application "System Events" to tell process "TextEdit" to set visible to false
-- Lion will auto-terminate the app
delay 5
tell application (path to frontmost application as text) to quit saving no

delay 5
tell application "System Events" to set pid to unix id of (process 1 where frontmost is true)
do shell script "kill " & pid

tell application "TextEdit" to close windows
tell application "System Events" to tell process "TextEdit" to set visible to false
-- Lion will auto-terminate the app
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文