LaunchD和Bing壁纸Shell脚本

时间:2015-04-06 20:11:26

标签: shell launchd

我试图使用bing壁纸下载器来安装mac& ubuntu(在这里找到:https://github.com/thejandroman/bing-Wallpaper)下载每日bing壁纸并将其设置为背景。如果我通过输入以下命令从终端运行它,脚本运行正常:

sh /Users/noahschneider/Pictures/wallpaper-changer/bing-wallpaper.sh

但是,当我尝试将其设置为launchD任务时,它不起作用。 launchD plist文件存储在/ Users / noahschneider / Library / LaunchAgents /中,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.ideasftw.bing-wallpaper</string>
        <key>ProgramArguments</key>
        <array>
            <string>/bin/bash</string>
            <string>/Users/noahschneider/Pictures/wallpaper-changer/bing-wallpaper.sh</string>
        </array>
        <key>LowPriorityIO</key>
        <true/>
        <key>Nice</key>
        <integer>1</integer>
        <key>StartCalendarInterval</key>
        <dict>
            <key>Hour</key>
            <integer>8</integer>
            <key>Minute</key>
            <integer>30</integer>
        </dict>
    </dict>
</plist>

这会调用bing-wallpaper.sh将当天的bing壁纸下载到文件夹中,如下所示:

#!/usr/bin/env bash

PICTURE_DIR="$HOME/Pictures/bing-wallpapers/"

rm -rf /Users/noahlschneider/Pictures/bing-wallpapers

mkdir -p $PICTURE_DIR

ONLYONE=0

while ! ping -W 1 -c 1 8.8.8.8 >&/dev/null; do sleep 10; done

urls=( $(curl -s http://www.bing.com | \
    grep -Eo "url:'.*?'" | \
    sed -e "s/url:'\([^']*\)'.*/http:\/\/bing.com\1/" | \
    sed -e "s/\\\//g") )

for p in ${urls[@]}; do
    filename=$(echo $p|sed -e "s/.*\/\(.*\)/\1/")
    if [ ! -f $PICTURE_DIR/$filename ] && [ $ONLYONE -eq 0 ]; then
        echo "Downloading: $filename ..."
        curl -Lo "$PICTURE_DIR/$filename" $p
        ONLYONE=$((ONLYONE+1))
    else
        echo "Skipping: $filename ..."
    fi

osascript /Users/noahschneider/Pictures/wallpaper-changer/next-wallpaper.scpt

done

这个脚本又调用一个苹果脚本来改变看起来像这样的壁纸:

tell application "System Events"
    set rotinterval to change interval of current desktop
    set change interval of current desktop to 1
    delay 1
    set change interval of current desktop to rotinterval
end tell

出了什么问题?以这种方式运行时脚本是否没有所需的管理员权限?谢谢!

0 个答案:

没有答案