Bash create calendar dialog with Zenity

Share this post to your friends !

This entry is part 2 of 13 in the series GUI for bash script using Zenity
Bash create calendar dialog with Zenity
5 (100%) 1 vote[s]

WriteBash - This article will guide you to write a small bash script using zenity to create a calendar dialog. Of course, with a very short line, the zenity will completed this work. But I want to write more about it so that new beginners can understand it more easily and using bash create calendar dialog.

Use Zenity simple command

When you use the --calendar option, you will create a calendar dialog. Zenity returns the selected date to standard output. If no date is specified on the command line, the dialog uses the current date.

zenity --calendar

You can see in the below image, a small calendar dialog is display. The selected date is the current date (at the time I write this article – 02/01/2018)

bash-create-calendar-dialog-with-zenity-01 Bash create calendar dialog with Zenity
Zenity calendar

Calendar dialog box supports options

The table below shows the options that the calendar dialog box supports. Note that these options will begin with two dashes at the beginning, because you may not see clearly in the table below:

All calendar options
OptionsMeaning
--text=textSpecifies the text that is displayed in the calendar dialog.
--day=daySpecifies the day that is selected in the calendar dialog. day must be a number between 1 and 31 inclusive.
--month=monthSpecifies the month that is selected in the calendar dialog. month must be a number between 1 and 12 inclusive.
--year=yearSpecifies the year that is selected in the calendar dialog.
--date-format=formatSpecifies the format that is returned from the calendar dialog after date selection. The default format depends on your locale. Format must be a format that is acceptable to the strftime function, for example %A %d/%m/%y.

For the --date-format option in the table above, you can see this link to learn more about the values contained in the strftime function.

Bash create calendar dialog

Our aim is to use the Bash combined with Zenity to create a calendar dialog.

The content of the script below:

#!/bin/bash
# Script author: Danie Pham
# Script site: https://www.writebash.com
# Script date: 02-01-2018
# Script use to create a calendar dialog by using Zenity
# Adding a habit of writing into functions will be useful when you write large programs.

f_create_calendar () {
    if zenity   --calendar \
                --title="Demo create calendar dialog - WriteBash.com" \
                --text="Click on a date to select that date." \
                --day=1 --month=1 --year=2018
        then echo $?
    else
        echo "No date selected"
    fi
}

# Main function
f_main () {
    f_create_calendar
}
f_main

exit

Copy the script above, assign permissions to script and execute script. The result will be as shown below. If you compare it to the image above the article, you will notice a difference.

chmod +x create_calendar

./create_calendar
bash-create-calendar-dialog-with-zenity-02 Bash create calendar dialog with Zenity
Script to create calendar

Conclusion

Indeed, the option to use the command zenity –calendar not difficult, it can be said is very very easy. However, I want to write an article that the reader can understand it most clearly.

Continue reading the series«« Previous part: Introduction Zenity simple GUI for BashNext part: Zenity create a notification icon »»
If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.


Share this post to your friends !
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

single post bottom banner
«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.