用 GeekTool 在桌面顯示年曆

GeekTool 可以將一些資訊顯示在桌面上,尤其是 Unix 的命令。用以下的 bash script 可以按假日、補上班日等以不同顏色顯示年曆,就不用常去翻日曆了。程式碼存檔得執行記得要用西元年當參數。顏色及特殊日子要隨年份修改,適合懂一些 Unix 的人用。可先在 Terminal 下執行看看,再用到 GeekTool 上。在我的桌面跑起來是這個樣子.

#!/bin/bash
year=$1
cal -y $year| awk -v year="`date +%Y`" -v month="`date +%m`" -v day="`date +%e` " '{

# List of special days
holiday[2012 "," 1 "," 23] = 23;
holiday[2012 "," 1 "," 24] = 24;
holiday[2012 "," 1 "," 25] = 25;
holiday[2012 "," 1 "," 26] = 26;
holiday[2012 "," 1 "," 27] = 27;
holiday[2012 "," 2 "," 27] = 27;
holiday[2012 "," 2 "," 28] = 28;
holiday[2012 "," 4 ", " 4] = 4;
holiday[2012 "," 5 ", " 1] = 1;
holiday[2012 "," 10 "," 10] = 10;
holiday[2012 "," 12 "," 31] = 31;
work[2012 "," 2 ", " 4] = 4;
work[2012 "," 3 ", " 3] = 3;
work[2012 "," 12 "," 22] = 22;
tradition[2012 "," 1 "," 23] = 23;
tradition[2012 "," 6 "," 23] = 23;
tradition[2012 "," 9 "," 30] = 30;

# Colors
holiday_color="31";
work_color="37";
tradition_color="34";
year_color="37";
today_color="33";

if (NR == 1) {
y = $1;
sub($1, "\033[1;" year_color "m&\033[0m", $0);
print $0;
next;
}
m = int((NR-3)/8)*3+1;
for (i=0; i<3; i++) {
t[i] = substr($0,1+i*22,20) " ";

for (j=0; j<7; j++) {
d = substr(t[i], 1+j*3, 2);
h[j] = y "," m+i "," d;
}

if ((i != 2) || (length(t[i]) == 21))
sub("...$", "\033[0;" holiday_color "m&\033[0m", t[i]);
sub("^...", "\033[0;" holiday_color "m&\033[0m", t[i]);

for (j=0; j<7; j++) {
x = h[j];
if (holiday[x] > 0) {
sub(holiday[x] " ","\033[0;" holiday_color "m&\033[0m",t[i]);
}
if (work[x] > 0) {
sub(work[x] " ","\033[1;" work_color "m&\033[0m",t[i]);
}
if (tradition[x] > 0) {
sub(tradition[x] " ","\033[0;" tradition_color "m&\033[0m",t[i]);
}
}

if (m+i==month && y==year)
sub(day,"\033[1;" today_color "m&\033[0m",t[i]);
}

print t[0],t[1],t[2];

}'
2011-11-16 22:48 發佈
好棒!

感謝分享,對不會指令編寫的人是好物!!
評分
複製連結