Skip to content

Instantly share code, notes, and snippets.

@markisatacomputer
Last active March 7, 2017 13:32
Show Gist options
  • Save markisatacomputer/b8724e0df85d265b9df3921a98fc6587 to your computer and use it in GitHub Desktop.
Save markisatacomputer/b8724e0df85d265b9df3921a98fc6587 to your computer and use it in GitHub Desktop.
osx webcam 2 bg
on run argv
tell application "System Events"
set desktopCount to count of desktops
repeat with desktopNumber from 1 to desktopCount
tell desktop desktopNumber
set picture to item 1 of argv
end tell
end repeat
end tell
--beep
end run
#!/bin/bash
#
# run on cron every min
#
CAMURL="$1"
CAMNAME="$2"
KEEP=10 # keep this many webcam images
OLD=(`ls -t ~/BGs/${CAMNAME}-*`) # store old filenames in array
NAME="~/BGs/${CAMNAME}-$(date +%s).jpg" # create new filename
# download current webcam image
/usr/local/bin/wget -O "$NAME" $CAMURL
# if successful continue
if [ $? -ne 0 ]
then
# update current background
osascript ~/scripts/backgroundz.scpt $NAME
# cleanup - remove files that are older than tenth
NUMBG="${#OLD[@]}"
if [ $NUMBG > $KEEP ]
then
i=$KEEP
while (( $i < $NUMBG ))
do
rm ${OLD[$i]}
i=$(($i+1))
done
fi
fi
*/3 * * * * /bin/bash ~/scripts/backgroundz.sh http://qt.exploratorium.edu/roofcam/Observatory/image.jpg observatory > /dev/null 2>&1
2-59/15 * * * * /bin/bash ~/scripts/backgroundz.sh http://warschauerstr-berlin.contempo-webcam.de/webcam.jpg berlin > /dev/null 2>&1
1-59/3 * * * * /bin/bash ~/scripts/backgroundz.sh http://210.157.212.207/SnapshotJPEG?Quality=Clarity&dummy=image.jpg japan > /dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment