Read the statement by Michael Teeuw here.
A command to refresh magic mirror page
-
Hi all! Previously I was working on a course project based on magic mirror, and it’s required that the smart mirror could be refreshed by a command (because I updated the config.js). I searched around the forum but didn’t find any ready-to-run command. Luckily, I finally figured it out, and would like to share with those who might need it in the future!
Firstly, here’s the one-line solution:
xdotool windowactivate --sync $(xdotool search --class electron | awk 'FNR == 3 {print}') key ctrl+r
You might already know that we can use keyboard stroke “ctrl+R” to refresh the smart mirror, and the command above is basically emulating this behavior. As for preparation, you need to use apt-get to download xdotool, which is used to send keyboard stroke command to a given window, in our case the smart mirror. Now I would explain this command in steps:
xdotool search --class electron
This command searches for existing windows whose name includes “electron”. From my observation, I found that this word “electron” appears in the name of our smart mirror window (though I don’t know what electron is).
awk 'FNR == 3 {print}'
From the previous step, 3 windows were found. In my case, the 3rd one is the smart mirror window that I’m interested in (maybe in your case it’s not, so remember to test it out!). This command selects it out.
xdotool windowactivate --sync ... key ctrl+r
This command sends the keystroke “ctrl+R” signal to the window we located in the previous steps.
Hope this would help!
-
@joezie Thank you very much for this. On my Raspberry PI 5, I did this to get it to work:
apt install xdotool
nano refreshMagicMirror.sh
#!/bin/bash # refreshMagicMirror.sh export DISPLAY=:0 xdotool windowactivate --sync $(xdotool search --name magicmirror) key ctrl+r
chmod og+x refreshMagicMirror.sh
To use this script:
. refreshMagicMirror.sh
or
/home/<username-here>/refreshMagicMirror.sh
assuming the script is in your user account’s home directory.Without setting the DISPLAY=:0 manually, xdotool wasn’t able to figure out which display to run on. By using the --name magicmirror instead of the --class search, it was able to find the one window named magicmirror so no need to awk out the third line entry of the --class results.
I hope this helps someone as much as your post helped me solve this. I like refreshing the screen remotely way more than restarting the service!
-
@quarky42 for those using the newer OS versions, bookworm, using wayland by default instead of x11
you need WAYLAND_DISPLAY=wayland-?
? is something , 0 or 1 usually