![]() ![]() Wait a few seconds, then press and hold the power button again to reboot your computer. (Note: Only use this option as a last resort if the other options do not work.) Press and hold the power button until your computer shuts down. Your computer will immediately shut down and restart after a few minutes. Additionally, this option does not work with Touch ID sensors.) Press Control+Command+Power button or Control+Command+Eject keys at the same time. (Note: Choosing this option may cause you to lose any unsaved work. Once your computer has shut down completely, wait a few seconds then press and hold the power button to reboot your computer. Your computer will shut down at the specified time. Press the Enter key and enter your password when prompted. If you’d like to schedule a reboot for a future time, replace “now” with the specified number of minutes in the future you would like to perform the shutdown. (Note: This option is not ideal for users who are unfamiliar with using a command-line interface.) Open the Terminal application. Your computer will shut down immediately and restart after a few minutes. Select the Restart button in the window that appears. ![]() (Note: This option does not work with Touch ID sensors.) Press the Control+Power button or Control+Eject keys at the same time. Your computer will shut down automatically and restart after a few minutes. Source: /usr/src/homeassistant/homeassistant/components/shell_command/_init_.There are four primary ways you can reboot your Mac computer:Ĭlick the Apple icon in the top left corner of your Mac screen. Here is the error I get, but I know that is not related Unfortunatelly when I run it from lovelace it doesn’t work.Īlthough it does work from terminal, all the times. service: shell_command.shutdown_imac_right Shutdown_imac_right: ssh -i /config/ssh_keys/id_rsa "sudo shutdown -h now"Īfter that I create a script as follows: alias: shutdown imac right So, I go ahead and I create the shell command as follows: #shutdown imac right ssh -i /config/ssh_keys/id_rsa "sudo shutdown -h now" When I run the following command from HA terminal everything works smoothly and imac shuts down. (of course, replace to get full name of current user with to shut down, it’s easier to test without rebootingįollow up my previous post, another problem came up So, remove the leading echo, and you have what you want: ssh localhost 'osascript -e '"'"'tell application "System Events" to get full name of current user'"'" There are many ways to provide the proper quotes, the trick here is to end the initial single quote with a single quote, then start double with single inside, and terminate double and start single again… Gives: ssh localhost osascript -e 'tell application "System Events" to get full name of current user' The cmdlet is just calling the native command /sbin/shutdown. ![]() Osascript expects a single arg after the -e, but the ssh execution gives 3 strings to execute on remote side, which, after shell evaluation loses the quotes, so you can test this: echo ssh localhost 'osascript -e '"'"'tell application "System Events" to get full name of current user'"'" In PowerShell 7.1, Stop-Computer was added for Linux and macOS. Gives ssh -i /config/ssh_keys/id_rsa osascript -e tell app "System Events" to shut downĪs you can see single quotes are “lost” (because evaluated by shell on remote side) Simply add an echo at the beginning, and you will “see” what is executed: echo ssh -i /config/ssh_keys/id_rsa osascript -e 'tell app "System Events" to shut down' (if you need only the shutdown, you can also specify it): something like: (“user” is the actual username) user ALL = NOPASSWD: /sbin/shutdownĬoncerning your initial request, using osascript, the issue is about argument values… Personally I prefer the solution that is more unix-ish, than mac-ish.Īnd right, I would add that line to /etc/sudoers
0 Comments
Leave a Reply. |