skip to Main Content

Some apps like Telegram or Slack starts wide open even with set in "Hide mode" on Mac login

There are some script or config to force an app to launch in hide mode ?

With Applescript I already try:

tell application "Mail" to launch
tell application "System Events" to set visible of process "Mail" to false

But is not what I search

2

Answers


  1. In vanilla AppleScript, the launch command is supposed to launch an app in the background, but not hidden. Some apps use panels for their interfaces (rather than normal windows) and panels tend to pop up to the head of the window hierarchy, so launch doesn’t really help. I could muck around trying to find a pure AppleScript solution to this, but in this case it’s straightforward to invoke objective-C (requires Leopard or above).

    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:
    

    To run this at login, you’ll either want to turn it into an AppleScript application that you can put in the Login Items, or write a launchd agent that runs the script at login. See this question’s answers.

    I’ve tested this on Telegram, but not Slack…

    Login or Signup to reply.
  2. For those not already importing Objective-C frameworks, then you’ll want to avoid the overhead of doing so by sticking to vanilla AppleScript, for which one can simply use the run command for a silent launch:

    run application "Mail"
    run application "Telegram"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search