GeekTool cal with a difference

Discussion in 'Mac Apps and Mac App Store' started by Mal, Jan 20, 2009.

  1. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #1
    I'm looking for help with a little project of mine. I'm looking to modify the cal command that I've seen used for calendars in GeekTool to create a horizontal calendar. I don't care about days of the week so much, I just think it would be interesting to have all of the days of the week listed out in order at the bottom of my screen, with the current one marked.

    So, I need two things:

    I need to strip out of the cal command the days of the week at the top (or repeat them the appropriate number of times, but I imagine that will be far more difficult) and the line breaks at the end of each week. This is the most important part.

    Secondly, I'd like to find a way to add bars (like this: |) on either side of the current date without replacing the numbers as most of the calendars I've seen have done it.

    Here's the code I've seen:
    Code:
    cal | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/././g') /"
    If I can just modify that to get what I want, that's fine, if I have to use something completely different, that's fine. I just would love to have a horizontal calendar.

    jW
     
  2. BigFizz macrumors newbie

    Joined:
    Dec 3, 2009
    #2
    I realize this is almost a year later, but you can find what you're looking for here: http://www.macosxhints.com/article.php?story=20040625094428394

    There's a post in particular you could look at:

    Authored by: wallybear on Wed, Jul 7 2004 at 2:06PM PDT

    but since I also like highlighting, I'll drop this to you as well:

    cal_head=`cal | head -1`; cal_tail=`cal | tail -7`; today=`date "+%e"`; echo "$cal_head"; echo -en "${cal_tail/${today}/\033[1;32m${today}\033[0m}";


    Edit: here's the code:

    #!/bin/sh

    month=`date +%m`
    year=`date +%Y`

    nextMonth=$(($month+1))
    lastMonth=$(($month-1))

    if [[ $nextMonth -gt 12 ]]
    then
    nextMonth=1
    year=$(($year+1))
    fi

    if [[ $lastMonth -eq 0 ]]
    then
    lastMonth=12
    year=$(($year-1))
    fi

    doCal()
    {
    cal $lastMonth $year
    cal | awk '{ if (substr($0,1,2) == " 1") print " 1 "; \
    do { prevline=$0; if (getline == 0) exit; print " "\
    substr(prevline,0) " "; } while (1) }' | \
    awk -v cday=`date "+%d"` '{ a=$0; sub(" "fill int(cday)" ","["fill int(cday)"]",a); print a };'
    echo
    cal $nextMonth $year
    }


    doCal | pr -3 -t

    if you can figure out how to incorporate that into a horizontal calendar, more power to you. (I haven't tried yet :) )
     

Share This Page