No internet connection
  1. Home
  2. How to

Open and Close app

By Mike Avenaim @Mike_Avenaim
    2020-12-03 19:43:30.952Z

    Hi all,

    Wondering if there is a way to setup the stream deck button so that once the application is open, i can then push the button again to close that window. This is my code to open the app:

    sf.file.open({
        path: "/Applications/Messages.app",
    });
    
    

    Thank you

    • 7 replies
    1. This will open Messages if it's not open and quit Messages if it is open

      if (!sf.ui.app('com.apple.iChat').mainWindow.exists) {
          sf.ui.app('com.apple.iChat').appEnsureIsRunningAndActive();
      } else {
          sf.ui.app('com.apple.iChat').menuClick({
              menuPath: ["Messages", "Quit Messages"],
          });
      }
      1. this will open Messages if not open and if it is it will hide it.

        if (!sf.ui.app('com.apple.iChat').mainWindow.exists) {
            sf.ui.app('com.apple.iChat').appEnsureIsRunningAndActive();
            globalState.messagesIsOpen = true
            throw 0
        }
        if (globalState.messagesIsOpen == true) {
            sf.ui.app('com.apple.iChat').menuClick({
                menuPath: ["Messages", "Hide Messages"],
            });
            globalState.messagesIsOpen = false
            throw 0
        }
        
        sf.ui.app('com.apple.iChat').appActivateMainWindow();
        globalState.messagesIsOpen = true;
        
        
      2. M
        In reply toMike_Avenaim:
        Mike Avenaim @Mike_Avenaim
          2020-12-03 20:40:21.586Z

          Hi,

          Thanks for this but it doesnt seem to open the MESSAGES app

          1. M
            In reply toMike_Avenaim:
            Mike Avenaim @Mike_Avenaim
              2020-12-03 20:51:03.631Z

              Hold up... I got it to work with your code.. FOr some reason it wasnt working and now it is... lol

              Thank you!

              1. It can be a bit confusing. Internally, in Mac OS, Messages is referred by it's old name iChat for backwards compatibility with older OS's

                1. MMike Avenaim @Mike_Avenaim
                    2020-12-03 21:10:28.885Z

                    Awesome... Thank you. Im going to try and apply this code to some other apps too

                2. F
                  In reply toMike_Avenaim:
                  Freddie Spells @Freddie_Spells
                    2023-03-18 07:09:03.720Z

                    Hi
                    I am trying to transfer this to any other app like f.e. open and close safari but I do not get the result I am aiming for.
                    I simply want to close the app when I push the button the second time on my Deck.
                    Maybe I just need another example from you with safari to get my head wrapped around this?
                    Thx!