Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bchery21

macrumors 6502a
Original poster
Aug 3, 2009
783
586
Boston, MA
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 % 4 )) -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 [ $(( ++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"


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

Thanks
 

Attachments

  • Screen shot 2013-08-02 at 6.20.24 PM.png
    Screen shot 2013-08-02 at 6.20.24 PM.png
    158 KB · Views: 310

tag

macrumors 6502a
Apr 29, 2005
918
9
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"
 

bchery21

macrumors 6502a
Original poster
Aug 3, 2009
783
586
Boston, MA
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...

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!
 
Last edited:

Macinsky

macrumors newbie
Sep 3, 2014
3
0
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!

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. :)
 

bchery21

macrumors 6502a
Original poster
Aug 3, 2009
783
586
Boston, MA
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. :)

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.
 

allanq

macrumors newbie
Nov 2, 2014
6
11
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
 

Macinsky

macrumors newbie
Sep 3, 2014
3
0
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


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"
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.