• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

A command to refresh magic mirror page

Scheduled Pinned Locked Moved General Discussion
3 Posts 3 Posters 711 Views 3 Watching
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.
  • J Offline
    joezie
    last edited by May 18, 2020, 2:30 AM

    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!

    Q 1 Reply Last reply 4 days ago Reply Quote 1
    • Q Offline
      quarky42 @joezie
      last edited by 4 days ago

      @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!

      S 1 Reply Last reply 4 days ago Reply Quote 0
      • S Away
        sdetweil @quarky42
        last edited by 4 days ago

        @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

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Enjoying MagicMirror? Please consider a donation!
        MagicMirror created by Michael Teeuw.
        Forum managed by Sam, technical setup by Karsten.
        This forum is using NodeBB as its core | Contributors
        Contact | Privacy Policy