【问题标题】:Is it possible to run an Automator workflow when a program exits?程序退出时是否可以运行 Automator 工作流程?
【发布时间】:2020-12-26 09:39:03
【问题描述】:

某些 macOS 程序有烦人的后台进程,当我退出程序时这些进程不会终止。有什么方法可以运行 Automator 工作流程,一旦我退出程序就结束该流程?

编辑:Adobe 为 AGMService 提供了一个卸载程序来永久删除它,绕过了这个问题的一部分。

【问题讨论】:

  • 这些程序有哪些?您可以创建自己的后台应用程序来注册 NSWorkspace 通知,但您需要知道这些后台进程是什么。
  • @red_menace Adob​​e Photoshop 和 Illustrator。后台进程是AGMService。

标签: macos automator


【解决方案1】:

根据 red_menace 的评论,您可以创建一个后台应用程序,该应用程序将等待 NSWorkspace 通知 Photoshop 或 Illustrator 已退出,然后退出 AGMService。将以下代码复制到脚本编辑器中(仔细检查 Illustrator 和 Photoshop 的本地化名称,尽管我认为它们是对的):

use AppleScript version "2.4"
use framework "AppKit"
use scripting additions

property NSWorkspace : class "NSWorkspace"

on run
    set workSp to NSWorkspace's sharedWorkspace()
    set notifCent to workSp's notificationCenter()
    tell notifCent to addObserver:me selector:"someAppHasTerminated:" |name|:"NSWorkspaceDidTerminateApplicationNotification" object:(missing value)
end run

on idle
    -- we don't use the idle loop, so tell the system let the app sleep. this comes out of idle once an hour
    return 3600
end idle

on someAppHasTerminated:notif
    set termedApp to (notif's userInfo's valueForKey:"NSWorkspaceApplicationKey")
    set termedAppName to (termedApp's localizedName) as text
    -- I'm guessing at the localized names for Photoshop and Illustrator. you may need to alter these
    if termedAppName is "Adobe Photoshop" or termedAppName is "Adobe Illustrator" then
        -- close the service here
        tell application "System Events"
            tell process "AGMService"
                if its accepts high level events is true then
                    tell application "AGMService" to quit
                else
                    do shell script "killall AGMService"
                end if
            end tell
        end tell
    end if
end someAppHasTerminated:

将其保存为应用程序,并选中“运行处理程序后保持打开”框:

然后将其添加到您的启动项中,以便在您登录时运行。然后,每当您退出 Illustrator 或 photoshop 时,它也应该强制 AGMService 退出。 (我不知道如果您在另一个仍然打开的情况下退出是否会导致问题)。

如果您想将其设置为隐藏的后台应用程序 - 一个不会显示在 Dock 或可见程序列表中的应用程序 - 右键单击​​小程序的图标,选择“显示包内容”,然后向下导航直到您找到“info.plist”文件。在纯文本编辑器(如 TextWrangler 或纯文本模式下的 TextEdit)中打开该文件,并在以下键值对中进行编辑:

<key>LSUIElement</key>
<true/>

保存,关闭文件和包,应用程序将不可见地运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 2010-11-04
    相关资源
    最近更新 更多