Alfred使用AppleScript来实现一键隐藏功能(老板键)

AI 摘要

Mac自动化脚本:隐藏指定进程,提升工作效率。快速隐藏WeChat、QQ等进程,提高生产力,点击了解详细教程!

![](https://img2024.cnblogs.com/blog/3408671/202403/3408671-20240328111025689-866975774.png)

![](https://img2024.cnblogs.com/blog/3408671/202403/3408671-20240328111043619-1351632497.png)

更新: > 2024.04.15 如果某个进程不判断捕获异常,使得代码能够继续执行

set appNames to { "WeChat", "QQ"}

tell application "System Events"
    repeat with appName in appNames
        try
            set appProcess to first process whose name is appName
            set appId to id of appProcess
            tell process appName
                set visible to false
            end tell
        on error errMsg
            -- Ignore error if process does not exist
        end try
    end repeat
end tell

~~set appNames to {"WeChat","QQ"} -- 将要隐藏的进程名称放入数组中~~

~~tell application "System Events"~~ ~~repeat with appName in appNames~~ ~~set appProcess to first process whose name is appName~~ ~~set appId to id of appProcess~~ ~~tell process appName~~ ~~set visible to false~~ ~~end tell~~ ~~end repeat~~ ~~end tell~~