Yad Clock script

Forum Forums General Software Yad Clock script

Tagged: 

  • This topic has 18 replies, 5 voices, and was last updated Jun 21-8:19 pm by Brian Masinick.
Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #84531
    Moderator
    Brian Masinick

      I’ve seen a Yad Alarm Clock that actually has a digital clock contained in it (a topic in the PCLinuxOS Forum and Magazine have carried it in the past).

      I’ve been looking to build a very simple clock that can have its own small detached box. I *can* and have written a very simple script to put the date and time in the top left corner of a terminal window, but I’ve not been successful with the appropriate logic to display the date and time in a small detached yad box. Can anyone show me how to do this?

      Here’s the simple script I wrote to display a clock in a terminal window:

      loop=1
      while (( loop )); do
        clear
        date +"%b %d, %Y  %r"
        sleep 0.5s
      done

      There have to be a few simple flags or arguments I could add to a yad line (or a couple of lines) to put this logic into a small independent box.
      Do we still have people here familiar enough with yad to provide the missing logic? Thanks for any help you can offer.

      --
      Brian Masinick

      #84541
      Moderator
      Brian Masinick
        Helpful
        Up
        0
        ::

        I was given a simple script:

        while :
        do
        date +"b %d, %Y  %r"
        sleep 0.5s
        done 2>&1 | yad --title=clock --posx=20 --posy=20 --width=220 --form   --cycle-read --field=": " --no-buttons --undecorated &

        EDIT: now that I have the concept down, made a few minor changes:
        1) Typo: --title-clock
        2) Width --width=220 makes AM or PM fit better

        • This reply was modified 10 months, 3 weeks ago by Brian Masinick.
        • This reply was modified 10 months, 3 weeks ago by Brian Masinick.

        --
        Brian Masinick

        #84569
        Member
        oops
          Helpful
          Up
          0
          ::

          I was given a simple script:

          while :
          do
          date +"%b %d, %Y. %r"
          sleep 0.5s
          done 2>&1 | yad --title_clock --posx=20 --posy=20 --width=200 --form   --cycle-read --field=": " --no-buttons --undecorated &

          Hi, nice small yad script Brian.

          # %r For 12h00 clock, %R for 24h00
          date +”%b %d, %Y. %r”

          
          #!/bin/bash
          while :
          do
          #date +"b %d, %Y. %r"
          date +" j:%j s:%W - %a %d %b, %Y. %R:%S"
          sleep 0.5s
          done 2>&1 | yad --title_clock --posx=20 --posy=20 --width=200 --form   --cycle-read --field=": " --no-buttons &
          • This reply was modified 10 months, 3 weeks ago by oops.
          #84572
          Member
          calciumsodium
            Helpful
            Up
            0
            ::

            I use the simpler:

            
            $ date +"%c"
            Tue 14 Jun 2022 07:10:50 AM CDT
            
            #84581
            Moderator
            Brian Masinick
              Helpful
              Up
              0
              ::

              Yeah, that works too.

              Being from the USA and learning a different format, the strings I used, though probably not ISO format, they are what I am most familiar with, hence the ‘curious’ format.

              --
              Brian Masinick

              #84582
              Moderator
              Brian Masinick
                Helpful
                Up
                0
                ::

                … and yes, I do know about each of the other strings and formats.
                As I said, I am used to visually seeing Month Day, Year, Hour: Minutes:Seconds AM/PM.

                I’m glad we are able to each choose the strings in the way we prefer; that’s the power of free software!

                --
                Brian Masinick

                #84599
                Member
                blur13
                  Helpful
                  Up
                  0
                  ::

                  xclock does exactly this

                  man xclock for options

                  its installed by default in antiX (I think)

                  #84601
                  Moderator
                  Brian Masinick
                    Helpful
                    Up
                    0
                    ::

                    xclock does exactly this

                    man xclock for options

                    its installed by default in antiX (I think)

                    While I agree, AND I have a clock (FoxClocks) in my browser, a clock in my task bar, and more than one “clock” program, I was simply looking for an exercise to at least “slightly” improve what I can do with Yad scripts. Yes, I’ve read the Yad pages, yes, I’ve looked at many programs and examples, but being (a retired) software engineer, every so often I still like to experiment with technology. I wasn’t “getting it” though, so I reached out in a few places, and one of my other technical sites had a sharp fellow who not only answered me, he provided me with a quickly usable solution, which I can now tinker with.

                    In addition to Yad there is another scripting language that I used to use quite often as a UNIX engineer: TCL with Tk graphics. There are other extensions to TCL, including Tkinter and others with either Python or Perl extensions. I do have a Tk “wish” script that I still have that allows me to open a simple bar, from which I can select whatever tools I wish to include; mine currently has Firefox, Emacs and Vim; I’ve changed it over the years. I believe somewhere in my archives I also have a TCL/Tk clock that is VERY similar to the Yad clock, so yeah, there are PLENTY of alternatives; I HAVE used xclock with my own colors, size, height, and X/Y coordinates too. I may resurrect that; this was simply a practice exercise so that I don’t lose 100% of my aging skills. (My skills are already “out of date” with the current generation of engineers!) 🙂

                    I share my outputs to:

                    1) Provide history for this work in a topic that I did create,
                    2) Share the information so that anyone interested in doing similar things (and modifying them to suit their own purposes) is free to do so, and
                    3) Demonstrate once again that even in a very light, lean distribution like ours, there are many variations of things that you can do at minimal expense and effort to customize whatever you want.

                    --
                    Brian Masinick

                    #84602
                    Moderator
                    Brian Masinick
                      Helpful
                      Up
                      0
                      ::

                      BTW, if I do want to use xclock, (I just did), here is one way:

                      xclock -d -strftime “%b %d, %Y %r” -update 1 2>&1 >/dev/null &
                      (I created xclock.txt so that you can copy this line in a file instead of having to modify the ” “). Notice that I originally had xclock.bash; that was rejected by the forum; I renamed it to xclock and it still wasn’t happy, so I turned it into a simple txt file and it worked; anyone who wants to attach files may have to use a similar technique and rename the file afterward).

                      This displays an xclock —> -d provides a digital clock, -strftime specifies the date format (and this is the one I prefer), -update 1 modifies the clock each second, 2>&1 —> File descriptor 1 is the standard output (stdout).
                      File descriptor 2 is the standard error (stderr).

                      Here is one way to remember this construct (although it is not entirely accurate): at first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as “redirect stderr to a file named 1”. & indicates that what follows and precedes is a file descriptor and not a filename. So the construct becomes: 2>&1. (This description was copied from stackoverflow.com questions about stdout and stderr).

                      The final & backgrounds the xclock process, so yes, this is a relatively standard way to start xclock, which I *could* implement in my .bashrc or other startup scripts.

                      • This reply was modified 10 months, 3 weeks ago by Brian Masinick.
                      • This reply was modified 10 months, 3 weeks ago by Brian Masinick.
                      • This reply was modified 10 months, 3 weeks ago by Brian Masinick.
                      Attachments:

                      --
                      Brian Masinick

                      #84618
                      Member
                      blur13
                        Helpful
                        Up
                        0
                        ::

                        Great work Brian!

                        For anyone else trying to copy paste that xclock line from the forum into the terminal, you have to manually delete the quotation marks and make new “straight” ones. The forum mangles the formating.

                        #84630
                        Moderator
                        Brian Masinick
                          Helpful
                          Up
                          0
                          ::

                          I’m not quite “done” with my tool scripting “practice”. The other tool I used to use in the peak of my development days was TCL/Tk. I’d use this along with Bash or ksh scripts to evaluate and mark with color emphasis code change. One of my development leads, (whose name was also Brian) wrote some code for me, and I applied it to several different ideas and scripts to create a toolchest of development tools for our project. Once he wrote the core, I wrote an entire series of scripts and used several similar ideas when I later worked on contracts. On the UNIX development projects we were able to use TCL/Tk; on contract projects, I usually had to stick with a simple, compatible shell core – and even there, I did my best to utilize features that could be used in sh, ksh, bash, or zsh.

                          So my final tool in this series, for my “retirement” practicing, will be a Bash – TCL/Tk clock script. I’ll see how long it takes me to get it right.

                          --
                          Brian Masinick

                          #84632
                          Member
                          marcelocripe
                            Helpful
                            Up
                            0
                            ::

                            For anyone else trying to copy paste that xclock line from the forum into the terminal, you have to manually delete the quotation marks and make new “straight” ones. The forum mangles the formating.

                            Thank you very much Blur13, now I understand why this third clock script didn’t work for me.

                            – – – – –

                            For anyone else trying to copy paste that xclock line from the forum into the terminal, you have to manually delete the quotation marks and make new “straight” ones. The forum mangles the formating.

                            Muito obrigado, Blur13, agora eu entendi porque nĂŁo havia funcionado para mim este terceiro script do relĂłgio.

                            #84735
                            Moderator
                            Brian Masinick
                              Helpful
                              Up
                              0
                              ::

                              I put my TCL scripts into another thread. The first TCL script in that thread displays two clocks, so I called it dualclock.

                              Regarding yad, those scripts are working well now. The only thing I still want to experiment with would be the inclusion of the yad clock in an extra script, which I can optionally include as either a startup service or a routine in my login script.

                              I’ll experiment with them and if I have anything interesting to add, I’ll share it in this thread.

                              One other thing: I have TWO working Python scripts that produce nice clocks. One is a very short script and it creates a very small clock that you can place nearly anywhere. The other one is a more elaborate clock with a large digital display and a colorful background. The elaborate one was not my personal creation, but the outcome of these experiments is that I have some useful code samples now in several scripting languages. I’m definitely NOT a scripting expert, nor have I ever been; I am pretty good at taking the work of others and using code segments to write something similar, and in some cases, create a completely new work. To me this is the value of freely available software. Even those like me who are not experts can certainly write some good code when there are good templates and good free source available!

                              So that’s really the moral of this story. Take a hobby and make something useful out of it and if it works, freely share it!

                              --
                              Brian Masinick

                              #84895
                              Moderator
                              Brian Masinick
                                Helpful
                                Up
                                0
                                ::

                                My longtime friend Dave Crouse, former owner of the USALUG (USA Linux Users Group) and current owner of a Slack site for former USALUG members to chat DID write to me and shared his version of a Bash function to display a clock; it’s very similar to one of my Bash scripts, except he put a created a function and put aborder around the function.

                                Put this in your .bashrc if you want a really simple command line clock:

                                function clock1
                                {
                                  while true; do clear
                                  echo "==========="
                                  date +"%r"
                                  echo "==========="
                                  sleep 1
                                  done
                                }
                                

                                --
                                Brian Masinick

                                #84896
                                Moderator
                                Brian Masinick
                                  Helpful
                                  Up
                                  0
                                  ::

                                  Once you source .bashrc again (or login again) you can type in clock1 in a terminal window and a simple clock will appear in the terminal.

                                  --
                                  Brian Masinick

                                Viewing 15 posts - 1 through 15 (of 19 total)
                                • You must be logged in to reply to this topic.