Tagged: "Yad Clock"
- This topic has 18 replies, 5 voices, and was last updated Jun 21-8:19 pm by Brian Masinick.
-
AuthorPosts
-
June 13, 2022 at 7:07 pm #84531Moderator
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 doneThere 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 MasinickJune 13, 2022 at 9:33 pm #84541Moderator
Brian Masinick
::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=220makes AM or PM fit better- This reply was modified 10 months, 4 weeks ago by Brian Masinick.
- This reply was modified 10 months, 4 weeks ago by Brian Masinick.
--
Brian MasinickJune 14, 2022 at 11:36 am #84569Member
oops
::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, 4 weeks ago by oops.
June 14, 2022 at 12:15 pm #84572Membercalciumsodium
June 14, 2022 at 2:46 pm #84581Moderator
Brian Masinick
::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 MasinickJune 14, 2022 at 2:53 pm #84582Moderator
Brian Masinick
::… 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 MasinickJune 14, 2022 at 8:45 pm #84599Member
blur13
::xclock does exactly this
man xclock for options
its installed by default in antiX (I think)
June 14, 2022 at 9:18 pm #84601Moderator
Brian Masinick
::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 MasinickJune 14, 2022 at 10:10 pm #84602Moderator
Brian Masinick
::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 MasinickJune 15, 2022 at 6:01 am #84618Member
blur13
::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.
June 15, 2022 at 12:49 pm #84630Moderator
Brian Masinick
::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 MasinickJune 15, 2022 at 2:38 pm #84632Member
marcelocripe
::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.
June 17, 2022 at 5:41 pm #84735Moderator
Brian Masinick
::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 MasinickJune 20, 2022 at 8:17 pm #84895Moderator
Brian Masinick
::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 MasinickJune 20, 2022 at 8:18 pm #84896Moderator
Brian Masinick
::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 -
AuthorPosts
- You must be logged in to reply to this topic.