【问题标题】:Block application on mac在 mac 上阻止应用程序
【发布时间】:2021-03-16 23:31:56
【问题描述】:

有没有办法在打开特定应用程序时运行简单的告诉应用程序退出。

例如,如果我打开 spotify,是否可以触发脚本退出应用程序。

谢谢!

【问题讨论】:

  • 1. Super User 是一个更适合系统管理员类型问题的论坛。 2. 控制对应用程序和服务的访问是 macOS 被轻描淡写的“家长控制”(系统事件 > 用户和组)的用途。

标签: macos applescript


【解决方案1】:

有没有办法在打开特定应用程序时运行简单的告诉应用程序退出。

简短回答:是的

更长的答案:

下面是我想到的几种方法...


有一个名为 EventsScripts 的付费应用程序,它可以对许多事件做出反应,其中一类是应用程序事件 其中包含 Application activatedApplication deactivatedApplication will launchApplication launchedApplication quit

EventsScripts 适用于 AppleScript 脚本shell 脚本

看看EventScripts。在发这篇文章时,它是$5.99 at the US App Store,但可以从开发者网站下载免费演示。

注意:我不隶属于 EventScripts 的开发者,只是该产品的满意用户。

示例 AppleScript 代码

on run eventArgs
    set thisTrigger to (trigger of eventArgs)
    if thisTrigger is "Application launched" then
        set appName to |applicationName| of eventArgs
        if appName is "Spotify" then
            tell application appName to quit
        end if
    end if
end run

Hammerspoon 是一种免费的替代方案,尽管人们可能会发现它不像例如事件脚本

这是一个示例,用于监视目标应用程序已启动的代码 然后使用 AppleScript code 关闭它:

示例 Lua 代码

function applicationWatcher(appName, eventType)
    if (eventType == hs.application.watcher.launched) then
        if (appName == "Spotify") then
            hs.applescript('tell application "Spotify" to quit')
        end
    end
end
appWatcher = hs.application.watcher.new(applicationWatcher)
appWatcher:start()

这将被放置在 ~/.hammerspoon/init.lua 文件中,并且 Hammerspoon 在后台运行,当目标应用程序启动,它被告知通过AppleScript退出。

注意:我不隶属于 Hammerspoon 的开发者,只是该产品的满意用户。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-21
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多