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
    5 Posts 4 Posters 951 Views 4 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

      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 Reply Quote 1
      • Q Offline
        quarky42 @joezie
        last edited by

        @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 Reply Quote 0
        • S Offline
          sdetweil @quarky42
          last edited by

          @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
          • F Offline
            FrostByte
            last edited by

            I would take a different approach. Start MagicMirror via ‘npm run server’ and you will get a website endpoint that you can access with a browser. The trick is that after you change the config.json, you can simply reload the webpage (F5). You can then start the browser in kiosk mode (so fullscreen) and automate F5 by external tools.

            S 1 Reply Last reply Reply Quote 0
            • S Offline
              sdetweil @FrostByte
              last edited by sdetweil

              @FrostByte as long as the change doesn’t affect a node_helper, which are only loaded at start time

              the config.js os loaded as part of the web page
              there is no notification it changed to the client browser

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              1 Reply Last reply Reply Quote 1
              • 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