39

Calendar with colored day

Posted in System by dvil88 3597 days ago

This is a simple script in php to get a calendar with today's day colored.

screenshot

PHP script: http://pastebin.com/f56e5608f

With this you get a calendar starting in Monday or Sunday with today's date in red, to change the color you only have to change '31' (red) in

echo chr(27),'[','31m',$color_day,chr(27),'[','0m';

The geeklet is configured to execute the script in /var/calendar.php, so if you save calendar.php somewhere else you will need to modify the path in the geeklet.

Geeklet files to download

Comments

User Avatar
fletch 3510 days ago
Thanks for the idea. This command is a lot less code, and faster too, since it doesn't need to fire up PHP:

cal | grep --color -C6 -E "(^| )$(date +%e)"

You can use the GREP_COLOR variable to change the default (red) to something else. This is green, for example:

cal | GREP_COLOR="32" grep --color -C6 -E "(^| )$(date +%e)"

Cheers!
User Avatar
jblubey 3505 days ago
@Fletch

i tried the two scripts you posted above, and while both of them showed the calendar, on neither was the current date highlighted (nothing was highlighted at all). what am i doing wrong? thanks! (SnowLeo 10.6.3)
User Avatar
kankei71 3483 days ago
cal | grep --color -C6 -E "(^| )$(date +%e)"

This works fine in the termainal but doesn't seem to work with geektool as you have to set up a font color. Or am I missing something?
User Avatar
Otaku 3466 days ago
how can u add the next month as well?
User Avatar
Russ77 3282 days ago
See my other comment below for adapting Fletch's original code.

@Otaku Paste the line below into another shell geeklet to have the next month displayed as well. The command line below should be safe to copy and paste into a shell window text box, because it doesn't require any backslashes or less than sign symbols.

cal $(date -v +1m "+%m %Y")

I found that piece of code with a google search. Remember to set a refresh time to have display update.
User Avatar
nBode 3427 days ago
So I'm new to this Geek stuff..

When I open the .glet file I just get a blank box.. What am I missing?
User Avatar
drumthordrum 3225 days ago
you need to do a few things...

1. download the .php script

2. set the destination of the geeklet to wherever you decide to save the .php file (make sure that the filenames are the same as well)

3. make sure the command in the geektool cmd line is php ~/locationOfFile/Filename.php
User Avatar
wontolla 3393 days ago
There seems to be a bug when you change start day to monday, and the first day of the month starts on a sunday (i.e. August 2010): it will print 8 days in the first week of the month.

Setting start day to sunday fixes it.
User Avatar
zuotian 3336 days ago
What do I put in the php file to set my time zone to Pacific?
User Avatar
drumthordrum 3225 days ago
Change

line 8 to:

date_default_timezone_set('Pacific/Apia')

Below is a list of timezones that you may use:

Pacific/Apia

Pacific/Auckland

Pacific/Chatham

Pacific/Easter

Pacific/Efate

Pacific/Enderbury

Pacific/Fakaofo

Pacific/Fiji

Pacific/Funafuti

Pacific/Galapagos

Pacific/Gambier

Pacific/Guadalcanal

Pacific/Guam

Pacific/Honolulu

Pacific/Johnston

Pacific/Kiritimati

Pacific/Kosrae

Pacific/Kwajalein

Pacific/Majuro

Pacific/Marquesas

Pacific/Midway

Pacific/Nauru

Pacific/Niue

Pacific/Norfolk

Pacific/Noumea

Pacific/Pago_Pago

Pacific/Palau

Pacific/Pitcairn

Pacific/Ponape

Pacific/Port_Moresby

Pacific/Rarotonga

Pacific/Saipan

Pacific/Samoa

Pacific/Tahiti

Pacific/Tarawa

Pacific/Tongatapu

Pacific/Truk

Pacific/Wake

Pacific/Wallis

Pacific/Yap
User Avatar
Russ77 3283 days ago
Two things to add to Fletch's suggestion to answer other comments above...

1. Use this command line that includes "**=always**" to ensure the highlighting of the current day within the geeklet, especially past any pipe characters. The command line below should be safe to copy and paste into a shell window text box, because it doesn't require any backslashes or less than sign symbols.

cal | GREP_COLOR="32" grep --color=always -C6 -E "(^| )$(date +%e)($| )"



2. Use a fixed width font to keep the line formatting aligned. I used Monaco font at size 18

Remember to set a refresh time to allow geeklet to update.

See my other tip above to display the next month as well.
User Avatar
Russ77 3281 days ago
Bonus Tip:

Most of the time it is better to copy and paste lines of code, rather than retype it. Not only is faster, but mistakes can be made while retyping "pipe" symbols, back slashes, forward slashes, single quote marks, double quote marks, and backticks. |\/'"`

Each symbol can mean something different in the code.

Paste it in, then make any substitutions pointed out by the author or that apply for your needs.
User Avatar
Russ77 3278 days ago
Sadly, another tip.

This is not meant to be a flame, but constructive criticism. This website is trying to do the community a service. I thank them.

However, the code authors and readers, in most cases, aren't aware that some of the code displayed is being mangled by this website's design. In the code display, less than signs or left angle brackets can't be used at all on this website and backslashes have to be double-backslashed to even show up as a single backslash. The designers of this website are 'apparently unaware' that they should be using some sort of 'tag' mechanism to display 'literal' 'code' 'examples' 'preformatted' so as to show us the unabridged code in the comments or elsewhere the author may want to place it on the website's webpages. I said the website designer are 'apparently unaware' because there is no prominent warning on each webpage about how inaccurate the displayed code may be.

So despite what I mentioned about copying and pasteing for accuracy, don't do it on this website, until the designers fix this webpage flaw. You can't be sure you are getting all the code unless you compare it to what is in the downloaded geeklet. You are better off just using the supplied geeklets that you can download, adapt, and implement.
User Avatar
sk0002 3154 days ago
To add another sometimes useful variation of fletch and Russ77's code above:

If you want to hide the "Month Year" title of the default cal output, and/or want to have a different sytle (background) of the current day highlighted, use this code:

cal | GREP_COLOR="47" grep --color=always -C6 -E "(^| )$(date +%e)($| )" | GREP_COLOR="8" grep --color=always -C6 -E "(^| )$(date +'%B %Y')($| )"

The first GREP_COLOR attribute ("47") in this case highlights the background behind the current day, so you can play with numeric values there (values in the 40ies change the background). The second GREP_COLOR attribute ("8") makes the current month and year in the title row of the cal output "translucent", i.e. it hides them.

 

 
User Avatar
s_selling 2991 days ago
Thanks,

great starting point, i used your code and after a few tweaks it is exactly what i wanted.
User Avatar
Jpatts 2991 days ago
I'm new to this, my problem for this one is I can't seem to get the dates to line up with the day of the month. What am I doing wrong?
User Avatar
nBode 2937 days ago
You'll probably have to change to a fixed-width font.

If you open the fonts window, "Fixed-Width" should be one of the collections on the left.
User Avatar
nBode 2937 days ago
Hey guys, so I'm using this code

`cal | GREP_COLOR="47" grep --color=always -C6 -E "(^| )$(date +%e)($| )" | GREP_COLOR="8" grep --color=always -C6 -E "(^| )$(date +'%B %Y')($| )"`

And last week, I noticed that the final row of the month was missing. So October ended at 29, there was no 30 & 31 on the next line.

Now, today, the 31st, the calendar has disappeared altogether. It just doesn't show up anymore. I can't figure out what's up.

Any help is appreciated!
User Avatar
always_a_newbie 2927 days ago
Thank you very much. This helps a lot.

Log in to comment or register here.