Geektool Help Needed - Calendar geeklet not working

Discussion in 'UI Customization' started by bchery21, Aug 2, 2013.

  1. bchery21 macrumors 6502

    bchery21

    Joined:
    Aug 3, 2009
    Location:
    Boston, MA
    #1
    I'll start off by saying I don't know much about coding. I took a couple coding classes in college but the science just wasn't for me. I do appreciate GeekTool though; all the simple code I've used I've found online. The following code is for a horizontal calendar. It worked flawlessly for the month of July but not so much for August.


    PHP:
    #!/bin/bash
    declare color="${1:-32}d=0 yy mm dd mon day wkd dow
    declare months=( 31 28 31 30 31 30 31 31 30 31 30 31 wkdays=( "Su" "Mo" "Tu" "We" "Th" "Fr" "Sa" )
    read yy mm dd mon < <(date "+%Y %m %d %b")
    [ $(( 
    yy )) -eq 0 ] && ${months[1]}=29
    wkd
    =$(date -jnu ${mm}010101${yy'+%w')
    mm=${months[$mm-1]}
    declare 
    line1="          " line2="\e[1;37m$mon $yy\e[0m  "
    while [ $(( ++)) -le $mm ]; do
      
    printf -v day "%02d" $d
      
    (( dow = ( wkd ) % ))
      [ 
    $dow -eq 0 -a $d -gt 1 ] && { line1="$line1  |"line2="$line2  |"; }
      [ 
    "$day== "$dd] && { line1="$line1\e[1;${color}m"line2="$line2\e[1;${color}m"; }
      
    line1="$line1  ${wkdays[$dow]}"line2="$line2  $day"
      
    "$day== "$dd] && { line1="$line1\e[0m"line2="$line2\e[0m"; }
    done
    printf 
    "$line1\n$line2\n"

    Would one of you fine coders be able to help me with this?

    Thanks
     

    Attached Files:

  2. tag macrumors 6502a

    tag

    Joined:
    Apr 29, 2005
    Location:
    PA, US
    #2
    I took a look at the script and there was an octal constant error during the months of August and September due to the months being identified as 08 and 09. Long story short the code can be fixed by either dropping the zeroes from in front of the months, or by changing the months entry to base-10. I did the former.

    The following code should work for you...

    Code:
    #!/bin/bash
    declare color="${1:-32}" d=0 yy mm dd mon day wkd dow
    declare months=( 31 28 31 30 31 30 31 31 30 31 30 31 ) wkdays=( "Su" "Mo" "Tu" "We" "Th" "Fr" "Sa" )
    read yy mm dd mon < <(date "+%Y %m %d %b")
    [ $(( yy % 4 )) -eq 0 ] && ${months[1]}=29
    wkd=$(date -jnu ${mm}010101${yy} '+%w')
    mm=${months#0[$mm-1]}
    declare line1="          " line2="\e[1;37m$mon $yy\e[0m  "
    while [ $(( ++d )) -le $mm ]; do
      printf -v day "%02d" $d
      (( dow = ( d + wkd - 1 ) % 7 ))
      [ $dow -eq 0 -a $d -gt 1 ] && { line1="$line1  |"; line2="$line2  |"; }
      [ "$day" == "$dd" ] && { line1="$line1\e[1;${color}m"; line2="$line2\e[1;${color}m"; }
      line1="$line1  ${wkdays[$dow]}"; line2="$line2  $day"
      [ "$day" == "$dd" ] && { line1="$line1\e[0m"; line2="$line2\e[0m"; }
    done
    printf "$line1\n$line2\n" 
     
  3. bchery21, Aug 8, 2013
    Last edited: Aug 8, 2013

    bchery21 thread starter macrumors 6502

    bchery21

    Joined:
    Aug 3, 2009
    Location:
    Boston, MA
    #3
    Man, thanks so much! I'm at work now but I'll def try it when I get home!

    EDIT: Works like a charm, thanks again!
     
  4. Macinsky macrumors newbie

    Joined:
    Sep 3, 2014
    #4
    I know this thread is kind of old, and thank you for the fix, but...

    There is another problem, all months end in 31 days. Another worlds, no matter what month it is the end day is the 31st. :eek:

    I tried to fix it but it's beyond me. If you can take a look and see if you can figure it out, I would be grateful.

    Cheers. :)
     
  5. bchery21 thread starter macrumors 6502

    bchery21

    Joined:
    Aug 3, 2009
    Location:
    Boston, MA
    #5
    Right, my calendar is the same way. But I have no idea how to fix this either; we would have to ask tag as he was he one who edited the code I found online to begin with.
     
  6. allanq macrumors newbie

    Joined:
    Nov 2, 2014
    #6
    Old thread but I looked at the code and made some tweaks. I verified it worked for Aug and Sept 2014 so you should be good in the future.

    Code:
    #!/bin/bash 
    declare color="${1:-32}" d=0 yy mm dd mon day wkd dow 
    declare months=( 31 28 31 30 31 30 31 31 30 31 30 31 ) wkdays=( "Su" "Mo" "Tu" "We" "Th" "Fr" "Sa" ) 
    read yy mm < <(date +'%Y %m')
    [ $(( yy % 4 )) -eq 0 ] && ${months[1]}=29 
    wkd=$(date -jnu ${mm}010101${yy} '+%w') 
    read mm dd mon < <(date +'%-m %d %b')
    mm=${months[$mm-1]} 
    declare line1="          " line2="\e[1;37m$mon $yy\e[0m  " 
    while [ $(( ++d )) -le $mm ]; do 
              printf -v day "%02d" $d 
                (( dow = ( d + wkd - 1 ) % 7 )) 
                  [ $dow -eq 0 -a $d -gt 1 ] && { line1="$line1  |"; line2="$line2  |"; } 
                    [ "$day" == "$dd" ] && { line1="$line1\e[1;${color}m"; line2="$line2\e[1;${color}m"; } 
                      line1="$line1  ${wkdays[$dow]}"; line2="$line2  $day" 
                        [ "$day" == "$dd" ] && { line1="$line1\e[0m"; line2="$line2\e[0m"; } 
                done 
                printf "$line1\n$line2\n"  
    
    Hope this helps you both.


    Allan
     
  7. Macinsky, Nov 5, 2014
    Last edited: Nov 5, 2014

    Macinsky macrumors newbie

    Joined:
    Sep 3, 2014
    #7

    THANK YOU for taking the time to fix it! It did not show up in GeekTool Mac at first, but a few changes and it worked. I also added the year and month name. Cheers.

    #!/bin/bash
    declare color="${1:-32}" d=0 yy mm dd mon day wkd dow
    declare months=( 31 28 31 30 31 30 31 31 30 31 30 31 )
    declare wkdays=("Mo" "Tu" "We" "Th" "Fr" "Sa" "Su")
    read yy mm < <(date "+%Y %m")
    read mes dia < <(date "+%b %A")
    [ $(( yy % 4 )) -eq 0 ] && ${months[1]}=29
    wkd=$(date -jnu ${mm}010101${yy} '+%w')
    read mm dd mon < <(date +'%-m %d %b')
    mm=${months[$mm-1]}
    declare line0=" \e[1;31m $mes $yy \e[0m"
    declare line1="\e[1;37m\e[0m " line2="\e[1;37m\e[0m "
    while [ $(( ++d )) -le $mm ]; do
    printf -v day "%02d" $d
    (( dow = ( d + wkd - 2 ) % 7 ))
    [ $dow -eq 0 -a $d -gt 1 ] && { line1="$line1 |"; line2="$line2 |"; }
    [ "$day" == "$dd" ] && { line1="$line1\e[1;${color}m"; line2="$line2\e[1;${color}m"; }
    line1="$line1 ${wkdays[$dow]}"; line2="$line2 $day"
    [ "$day" == "$dd" ] && { line1="$line1\e[0m"; line2="$line2\e[0m"; }
    done
    printf "$line0\n$line1\n$line2\n"
     

Share This Page