MAC桌面主题按时间段切换 在办公室也可以感受到外面世界一天的变化

 

#!/bin/bash
abc=`ps auxw |grep Mail|grep -v grep|awk '{print $3}'|awk -F '.' '{print$1}'`
if [ "##"$abc = "##""" ];then
    abc=0
    echo "mail not run "  >> /Users/beck/Pictures/Desktop\ Pictures/mail.log; 
    echo "time: "`date`  >> /Users/beck/Pictures/Desktop\ Pictures/mail.log; 
fi
if [ $abc -gt 90 ];then 
    ps auxw |grep Mail|grep -v grep|awk '{system("kill "$2)}'
    echo "mail cpu: "$abc  >> /Users/beck/Pictures/Desktop\ Pictures/mail.log; 
    echo "time: "`date`  >> /Users/beck/Pictures/Desktop\ Pictures/mail.log; 
fi

P_HOME=`echo /Users/beck/Pictures/Desktop\ Pictures/`
HOUR=`date +"%H"`
MINUTE=`date +"%M"`
MOD=`echo 1440`
NOW=`echo $HOUR*60+$MINUTE | bc`
if [ -f "$P_HOME""tmp.auto_change_desktop.dir.list" ]; then
    DIRS=`cat "$P_HOME""tmp.auto_change_desktop.dir.list"`
else
    find . -name '.DS_Store' -exec rm {} \;
    find "$P_HOME" -type d -depth 1  -exec basename {} \; > "$P_HOME""tmp.auto_change_desktop.dir.list" 
    DIRS=`cat "$P_HOME""tmp.auto_change_desktop.dir.list"`
fi
MIN_MINUS_RES=$MOD
MIN_DIR_NAME=""

for dir_name in $DIRS
do
    T_HOUR=`echo "$dir_name"|cut -d "." -f 1 `
    T_MINUTE=`echo "$dir_name"|cut -d "." -f 2 `
    MINUS_RES=`echo "( ( "$NOW" + "$MOD" ) - "$T_HOUR"*60 - "$T_MINUTE" ) % "$MOD | bc`
    if [ $MINUS_RES -le $MIN_MINUS_RES ];then
        MIN_MINUS_RES=$MINUS_RES
        MIN_DIR_NAME=`echo "$dir_name"`
    fi
done

#echo `osascript -e ' tell application "System Events" to get picture of its desktop ' ` >> "$P_HOME""tmp.log.debug"
CUR_SITUATION=`osascript -e ' tell application "System Events" to get picture of its desktop ' | awk -F '/' '{print $(NF-1)}'`
if [ x$CUR_SITUATION == x$MIN_DIR_NAME ]; then
    exit
fi

if [ -f "$P_HOME""tmp.auto_change_desktop.""$MIN_DIR_NAME"".count" ]; then
    FILE_COUNT=`cat "$P_HOME""tmp.auto_change_desktop.""$MIN_DIR_NAME"".count"`
else
    find . -name '.DS_Store' -exec rm {} \;
    regular_file_count=`find "$P_HOME""$MIN_DIR_NAME""/" -type f -depth 1  -exec basename {} \;|wc -l `
    symbolic_link_count=`find "$P_HOME""$MIN_DIR_NAME""/" -type l -depth 1  -exec basename {} \;|wc -l `
    echo $regular_file_count + $symbolic_link_count | bc  > "$P_HOME""tmp.auto_change_desktop.""$MIN_DIR_NAME"".count"   
    FILE_COUNT=`cat "$P_HOME""tmp.auto_change_desktop.""$MIN_DIR_NAME"".count"`
fi
if [ $FILE_COUNT -eq 0 ];then
    exit;
fi
SEL_RANDOM=`echo "$RANDOM" % "$FILE_COUNT" + 1 | bc`
if [ -f "$P_HOME""tmp.auto_change_desktop.""$MIN_DIR_NAME"".file_name_list" ]; then
    PIC_NAME=`cat "$P_HOME""tmp.auto_change_desktop.""$MIN_DIR_NAME"".file_name_list" |head -n "$SEL_RANDOM" |tail -n 1`
else
    find . -name '.DS_Store' -exec rm {} \;
    find "$P_HOME""$MIN_DIR_NAME""/" -type f -depth 1  -exec basename {} \; > "$P_HOME""tmp.auto_change_desktop.""$MIN_DIR_NAME"".file_name_list"
    find "$P_HOME""$MIN_DIR_NAME""/" -type l -depth 1  -exec basename {} \; >> "$P_HOME""tmp.auto_change_desktop.""$MIN_DIR_NAME"".file_name_list"
    PIC_NAME=`cat "$P_HOME""tmp.auto_change_desktop.""$MIN_DIR_NAME"".file_name_list" |head -n "$SEL_RANDOM" |tail -n 1`
fi
PIC_PATH=`echo "$P_HOME""$MIN_DIR_NAME""/""$PIC_NAME"`

NUM=3;
osascript -e "tell application \"System Events\" to tell every desktop to set picture to \"$PIC_PATH\""

CUR_PIC_PATH=`osascript -e ' tell application "System Events" to get picture of its desktop ' | awk -F ',' '{print $1}' `
while [ "$PIC_PATH" != "$CUR_PIC_PATH" -a $NUM -ge 0 ]
do
    sleep 60
    osascript -e "tell application \"Finder\" to set desktop picture to POSIX file \"$PIC_PATH\""
    CUR_PIC_PATH=`osascript -e ' tell application "System Events" to get picture of its desktop '`
    (( NUM -= 1 ))
done

 

 

 

我的主题设置:
  清晨一米阳光 上午树林和朝阳 中午可口午饭 午休时间 下午攀登山峰 傍晚美食或下午茶 晚上魔都夜景 深夜十字架教堂纯灰
优质高清桌面图片网站推荐:
https://unsplash.com/

使用感受:
之前在办公室离窗户远的时候,经常感受不到一天的变化,经常到饭点不觉得饿,到很晚仍觉得时间还早,现在这种现象缓解很多。

 
 
 

你可能感兴趣的:(日常办公小窍门)