Skip to content

Instantly share code, notes, and snippets.

@aphexddb
Last active May 14, 2023 05:10
Show Gist options
  • Save aphexddb/7876911 to your computer and use it in GitHub Desktop.
Save aphexddb/7876911 to your computer and use it in GitHub Desktop.
OSX sleepwatcher script to take a photo on wakeup and upload to dropbox
#!/bin/bash
#
# Mac camera auto upload script
#
#####################################################
# Generate filename based on date stamp
FILE_SRC=/tmp/$(date +%m%d%y%H%M%S).jpg;
DROPBOX_FOLDER=macbook
DROPBOX_UPLOADER=/Users/<username>/Dropbox-Uploader/dropbox_uploader.sh
# Take iSight Photo and store in /tmp with datestamp filename
/usr/local/bin/imagesnap -q $FILE_SRC;
# Wait a little while, if Mac is waking from sleep, needs a moment to connect to network
sleep 60;
# Generate semaphore for connectivity by pinging NASA
isconnected=$(ping -c 1 www.nasa.gov | grep 64 | wc | awk '{print $1}');
# If connected...
if [ "$isconnected" -eq "1" ]; then
for f in /tmp/*jpg;
do
$DROPBOX_UPLOADER upload $f $DROPBOX_FOLDER;
rm $f;
done
else
# If not connected.. leave captures there until next time.
echo "No Connection, Image not transferred or deleted.";
fi

OSX sleepwatcher script to take a photo on wakeup and upload to dropbox

  1. install Dropbox-Uploader

  2. install imagesnap

     $ brew install imagesnap
    
  3. install sleepwatcher

     $ brew install sleepwatcher
    
  4. Drop the .wakeup file in your home dir

@iby
Copy link

iby commented Sep 1, 2015

😄

@xXFracXx
Copy link

Doesn't work, did it step by step. Any help?

@agupt001
Copy link

agupt001 commented Feb 6, 2023

After $ brew install sleepwatcher
Just edit the file /etc/rc.wakeup to write your own wakeup command.
That's all, it should do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment