如何强制应用程序以隐藏模式启动? (Mac 登录应用程序)
How do I force apps to start in hide mode? (Mac Login Applications)
即使在 Mac 登录
时设置为“隐藏模式”,Telegram 或 Slack 等一些应用程序也会开始完全打开
有一些脚本或配置可以强制应用以隐藏模式启动?
我已经尝试使用 Applescript:
tell application "Mail" to launch
tell application "System Events" to set visible of process "Mail" to false
但不是我搜索的
在 vanilla AppleScript 中,launch
命令应该在后台启动一个应用程序,但不是隐藏的。一些应用程序在其界面中使用面板(而不是正常的 windows)并且面板往往会弹出到 window 层次结构的头部,因此 launch
并没有真正的帮助。我可以四处寻找一个纯 AppleScript 解决方案来解决这个问题,但在这种情况下,调用 objective-C(需要 Leopard 或更高版本)很简单。
use AppleScript version "2.4"
use framework "AppKit"
use scripting additions
set targetApp to "Telegram"
my openAppSilently:targetApp
on openAppSilently:appToOpen
set appPath to POSIX path of (path to application appToOpen)
set sharedWorkspace to current application's class "NSWorkspace"'s sharedWorkspace()
set appUrl to current application's class "NSURL"'s fileURLWithPath:appPath
set config to current application's class "NSWorkspaceOpenConfiguration"'s configuration()
set config's activates to false
set config's hides to true
sharedWorkspace's openApplicationAtURL:appUrl configuration:config completionHandler:(missing value)
end openAppSilently:
要 运行 在登录时使用它,您需要将其转换为可以放入登录项的 AppleScript 应用程序,或者编写一个 运行 脚本的启动代理在登录。参见 this question's answers。
我已经在 Telegram 上测试过了,但没有在 Slack 上测试过...
对于那些尚未导入 Objective-C 框架的人,您将希望通过坚持使用 vanilla AppleScript 来避免这样做的开销,为此可以简单地使用 run
静默启动命令:
run application "Mail"
run application "Telegram"
即使在 Mac 登录
时设置为“隐藏模式”,Telegram 或 Slack 等一些应用程序也会开始完全打开有一些脚本或配置可以强制应用以隐藏模式启动?
我已经尝试使用 Applescript:
tell application "Mail" to launch
tell application "System Events" to set visible of process "Mail" to false
但不是我搜索的
在 vanilla AppleScript 中,launch
命令应该在后台启动一个应用程序,但不是隐藏的。一些应用程序在其界面中使用面板(而不是正常的 windows)并且面板往往会弹出到 window 层次结构的头部,因此 launch
并没有真正的帮助。我可以四处寻找一个纯 AppleScript 解决方案来解决这个问题,但在这种情况下,调用 objective-C(需要 Leopard 或更高版本)很简单。
use AppleScript version "2.4"
use framework "AppKit"
use scripting additions
set targetApp to "Telegram"
my openAppSilently:targetApp
on openAppSilently:appToOpen
set appPath to POSIX path of (path to application appToOpen)
set sharedWorkspace to current application's class "NSWorkspace"'s sharedWorkspace()
set appUrl to current application's class "NSURL"'s fileURLWithPath:appPath
set config to current application's class "NSWorkspaceOpenConfiguration"'s configuration()
set config's activates to false
set config's hides to true
sharedWorkspace's openApplicationAtURL:appUrl configuration:config completionHandler:(missing value)
end openAppSilently:
要 运行 在登录时使用它,您需要将其转换为可以放入登录项的 AppleScript 应用程序,或者编写一个 运行 脚本的启动代理在登录。参见 this question's answers。
我已经在 Telegram 上测试过了,但没有在 Slack 上测试过...
对于那些尚未导入 Objective-C 框架的人,您将希望通过坚持使用 vanilla AppleScript 来避免这样做的开销,为此可以简单地使用 run
静默启动命令:
run application "Mail"
run application "Telegram"