Free cloudapp alternative

A few of my colleagues and me are using Cloudapp a lot to share screenshots. Lately w were getting fed up with the nagscreens of Cloudapp to pay so i quickly assembled a homebrewn solution for use on our Macbooks.

What we want to do is implement the following workflow:

Whenever we use the default screen-capture functions of OSX (ex: cmd-shift-3 or cmd-shift-4), upload the resulting screenshot to imgur and put the link to the url in our pastebuffer.

How can we do that?

  1. Monitor ~/Desktop for new .png files because OSX dumps screenshots on your Desktop. Here we’re going to use FSWatch.
  2. Fswatch will call a little shellscript to upload to http://imgur.com and put the url in our pastebuffer with pbcopy.

1. The upload script

Put the following in ~/scripts/imgur.sh.

#!/bin/bash
# 
# Upload image to imgur and put the url to the image in paste-buffer
#
# You need to register a CLIENT_ID at https://api.imgur.com/oauth2/addclient
#

CLIENT_ID="YOUR IMGURL CLIENT ID"
API_BASE=https://api.imgur.com/3/image.xml
IMAGE=$1

# echo "Incoming: $IMAGE" >> /tmp/imgurl.log
if echo $IMAGE | grep -q "Screen Shot.*\.png$" ; then
 #echo "IS SS: $IMAGE" >> /tmp/imgurl.log
 IMGURL=`/curl -s -F "image=@$IMAGE" -H "Authorization: Client-ID $CLIENT_ID" $API_BASE | grep -E -o "<link>(.)*</link>" | grep -E -o "http://i.imgur.com/[^<]*"`
 # echo $IMGURL >> /tmp/imgurl.log
 echo $IMGURL | pbcopy
 /usr/local/bin/terminal-notifier -message "$IMGURL" -title "IMGUR Screenshot"
fi

Make sure to make the file executable afterward:

chmod +x ~/scripts/imgur.sh

2. On El Capitan: Send notification

We also want a little notification when the upload is complete. For this we need Terminal Notifier.

brew install terminal-notifier

3. The filesystem watcher

Install FSWatch:

brew install fswatch

Put the following in ~/scripts/imgurfswatch.sh:

fswatch -0 --event=Created --event=Renamed ~/Desktop/ |xargs -0 -n 1 ~/scripts/imgur.sh

This script needs to be executable:

chmod 755 ~/scripts/imgurfswatch.sh

4. Start it automatically on boot

We want to start up the watcher automatically when we boot. For this we use Launchd.

Insert the following in ~/Library/LaunchAgents/com.cjware.imgurl.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
 <dict>
 <key>Label</key>
 <string>com.cjware.imgurl</string>
 <key>RunAtLoad</key>
 <true/>
 <key>StartInterval</key>
 <integer>15</integer>
 <key>KeepAlive</key>
 <true/>
 <key>Program</key>
 <string>/Users/<YOUR USER NAME HERE>/scripts/imgurfswatch.sh</string>
 <key>StandardOutPath</key>
 <string>/var/log/cjware_fswatch.log</string>
 <key>StandardErrorPath</key>
 <string>/var/log/cjware_fswatch.log</string>
 </dict>
</plist>

Touch the log-file:

touch /var/log/cjware_fswatch.log

Make it execute on boot:

launchctl load -w ~/Library/LaunchAgents/com.cjware.imgurl.plist

Little Numbers

Little Numbers:
How often have you thought: “Just how many coffees did i drink today?”
or: “How many pushups was i supposed to do?”
There are a lot of numbers to keep in mind during the day. These little widgets help you keep track of all those numbers.
Keep one to check how many calls you made. Or make one to count how many times your co-worker uses the phrase “oh my god” during a day.

So i needed an excuse to play with some new android-libs. It’s also the first time i’m writing an Android AppWidget. The API is a bit of a disappointment, to be honest. There’s lots of things you have to work around, like setting the background color of a widget, for instance. Those things should not require a programmer to jump through hoops to implement.

Then again, found a nice little ORM-library: Green DAO. And from now on, all my projects will use ActionbarSherlock.