TRIGGERcmd
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Log out user and Sleep on Mac?

    General Discussion
    mac log out sleep lauch daemon feature request
    3
    11
    1.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Nick LagangN
      Nick Lagang
      last edited by Russ

      Hi,

      I have a Mac and would like to know if there is a way to Log Out the active user first and then have it go to sleep. I have noticed that when I manually Log Out and give the Sleep command to Alexa, the TRIGGERcmd.app seems to have stopped running, so the Sleep command no longer works at the Log In screen.

      The reason for this is that I would like to always have a "clean session" when I wake the Mac and type my user password.

      Is there a way to run the TRIGGERcmd.app as a background app (launch daemon) before user login?

      Thanks!

      RussR 1 Reply Last reply Reply Quote 0
      • RussR
        Russ @Nick Lagang
        last edited by

        @Nick-Lagang, I haven't implemented a background option for macs yet. I'm thinking about how I could add that. I found this article just now:
        https://www.endyourif.com/node-js-as-a-background-service/

        If you're interested, I could try this myself and write a post about how to use it to run the agent in background mode on a mac, so you could use background commands that would run whether you're logged in or not.

        Russell VanderMey

        1 Reply Last reply Reply Quote 0
        • Nick LagangN
          Nick Lagang
          last edited by

          Hey @Russ, thanks for the reply! It would be great if you could please do that, in my case it would help out a lot!

          RussR 1 Reply Last reply Reply Quote 0
          • RussR
            Russ @Nick Lagang
            last edited by Russ

            @Nick-Lagang, here's how I did it on my mac:

            Using the root user, I created a /Library/LaunchDaemons/com.triggercmd.agent.plist file with these contents:

            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
            <plist version="1.0">
            <dict>
            <key>Label</key>
            <string>com.triggercmd.agent</string>
            
            <key>WorkingDirectory</key>
            <string>/Applications/TRIGGERcmdAgent.app/Contents/Resources/app</string>
            
            <key>ProgramArguments</key>
            <array>
            <string>/usr/local/bin/node</string>
            <string>src/daemon.js</string>
            <string>--run</string>
            <string>/Users/russ/.TRIGGERcmdData</string>
            </array>
            
            <key>RunAtLoad</key>
            <true/>
            
            <key>KeepAlive</key>
            <true/>
            
            </dict>
            </plist>
            

            You can copy that verbatim except you'll want to change /Users/russ in this line to /Users/(your user)

            <string>/Users/russ/.TRIGGERcmdData</string>
            

            Then just run these commands as root:

            launchctl load /Library/LaunchDaemons/com.triggercmd.agent.plist
            launchctl start /Library/LaunchDaemons/com.triggercmd.agent.plist
            

            You'll also need NodeJS installed for this to work.

            Now we can run background commands on our macs!

            You can use the GUI Command Editor to create the commands, but to make them background commands, you'll need to use the Text Command Editor to switch the ground field to background.

            This command worked just fine to turn off my display while I was logged off:
            3fe5a1a7-d5fb-46b6-b027-9c2f1a3a4a4e-image.png

            Russell VanderMey

            Nick LagangN 1 Reply Last reply Reply Quote 0
            • Nick LagangN
              Nick Lagang @Russ
              last edited by

              Hey @Russ you're a genius... I followed the steps and it works perfectly! I'm sure many other Mac users will find this very helpful! Thanks again for taking the time to look into this and give such an easy and fast solution...

              Now I'm having trouble setting up the Mac to wake on lan from sleep... I'm not sure if Triggercmd has this option... Do you know any way to set this up that actually works?

              Anyway, thank you!

              RussR 1 Reply Last reply Reply Quote 0
              • RussR
                Russ @Nick Lagang
                last edited by

                @Nick-Lagang, you're welcome. I'm glad it works for you.

                To wake your Mac up with wake-on-lan, you need another computer on your network to send a "magic packet" to your Mac. Do you have something that's always on? I use a Raspberry Pi to send the magic packet.

                You might want to try this first to understand how it works:
                https://computers.tutsplus.com/tutorials/how-to-remotely-wake-a-mac-with-an-ios-device--cms-21614

                Russell VanderMey

                1 Reply Last reply Reply Quote 0
                • Nick LagangN
                  Nick Lagang
                  last edited by Nick Lagang

                  I actually have a low power mini-itx pc with windows 10 that I could leave always on if needed to make this work. I've been doing some research on how to get it to wake my Mac but there's not many specific results, or maybe I'm not searching the right way lol... If not asking too much, do you have a way that you could point me, that could work? A Windows 10 pc waking a Mac on wake-on-lan... or maybe even a way over the internet...

                  RussR 1 Reply Last reply Reply Quote 0
                  • RussR
                    Russ @Nick Lagang
                    last edited by

                    @Nick-Lagang, I recommend using Nirsoft's WakeMeOnLan tool to send the magic packet from your Windows box:

                    You can use a command like this:

                    WakeMeOnLan.exe /wakeup 40-65-81-A7-16-23
                    

                    40-65-81-A7-16-23 would be your Mac's network interface card's mac address.

                    Russell VanderMey

                    1 Reply Last reply Reply Quote 0
                    • Nick LagangN
                      Nick Lagang
                      last edited by

                      Hey @Russ I installed WakeMeOnLan tool as you recommended, and got it to wake up my Mac locally, but I'm not sure how to make it work through Triggercmd on Alexa. Where should I run the command you said?

                      RussR 1 Reply Last reply Reply Quote 0
                      • RussR
                        Russ @Nick Lagang
                        last edited by Russ

                        @Nick-Lagang, you'd make a TRIGGERcmd trigger that runs this command on your Windows PC:

                        WakeMeOnLan.exe /wakeup 40-65-81-A7-16-23
                        

                        The replace 40-65-81-A7-16-23 with your Mac's mac address.

                        Russell VanderMey

                        1 Reply Last reply Reply Quote 0
                        • Renan CorreaR
                          Renan Correa
                          last edited by

                          Got a lot of issues with node + brew, this one worked like a charm for me:

                          osascript -e 'tell application "Finder" to sleep'
                          
                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post