Fan Zhen Coder & Teacher

自动设定国家地理的每日一图为Mac桌面

2016-05-20

daily-pic 的 Bash 脚本基础上修改而成:

#!/bin/bash

http.get.url.natgeo(){
    local BASE_URL='http://photography.nationalgeographic.com/photography/photo-of-the-day/'
    local IMAGE_BASE_URL='images.nationalgeographic.com'
    local image_url=$(
        curl -A "${USER_AGENT}" -k -s -o- "${BASE_URL}" |
        egrep -o -m1 "${IMAGE_BASE_URL}"'/.*[0-9]*x[0-9]*.jpg'
    )
    if [[ ! -z $image_url ]]; then
        echo 'http://'"${image_url}"
    fi
}

url=$(http.get.url.natgeo)
fname=${url##*/}

wget -P ~/Pictures/GeoWallpaper ${url}

osascript <<EOT
tell application "Finder"
set desktop picture to POSIX file "/Users/fanzhen/Pictures/GeoWallpaper/${fname}"

然后用 Lingon X 设置每天9点运行此脚本。 /bin/bash Natgeo.sh


Similar Posts

Comments