Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RickCogley/bfdbe717753dd989a813 to your computer and use it in GitHub Desktop.
Save RickCogley/bfdbe717753dd989a813 to your computer and use it in GitHub Desktop.
Mac OS X Folder Action Upload Screenshot to Google Drive.sh

Mac OS X Folder Action Upload Screenshot to Google Drive.sh

This script is for using with an OS X "folder action" created with "Automator", included with OS X.

It uses drive (https://github.com/odeke-em/drive), and assumes it is installed and set up. In this case, my "drive" has been initiated at ~/gdrive, and the subfolder Screenshots matches the same in my Google Drive.

  1. Use Automator to make a folder action to watch your screenshots folder, wherever that is.
  2. Paste the script in a "run shell script" action, selecting /bin/bash and "pass input as arguments".
  3. You can add a display notification if you like, that will popup an OS X notification when complete.

The script calls osascript which allows you to do AppleScript functions from the terminal. It pops up a dialog to grab some text to be entered into the screenshot's description field on Google Drive. This text is indexed and you can search on it for recall later. You could also rename the file as well, using a similar technique.

If the script works, you'll see a rotating gear icon in the Mac toolbar (at least it's been like this through El Capitan), a publicly shared screenshot will appear in your Drive/Screenshots folder, and, you'll have the URL on the clipboard, ready for pasting.

Mac screenshot settings

Change screenshot file type: defaults write com.apple.screencapture type png

Change screenshot file name: defaults write com.apple.screencapture name "JRC Screenshot"

Restart the relevant service: killall SystemUIServer

Confirm: defaults read com.apple.screencapture

#!/bin/bash
# Author: Rick Cogley
# Updated: 27 Jan 2016
# Purpose: For use in a Mac OS X automator action, set to watch a screenshot folder.
# Assumes:
# GOPATH is set
# drive is installed (https://github.com/odeke-em/drive)
# there is a folder initialized with "drive init"
DRIVEINITPATH=$HOME/gdrive
GOPATH=$HOME/gocode
EXIFTOOLBIN=/usr/local/bin/exiftool
CURRYEAR=$(date +'%Y')
EXIFAUTHOR="Rick Cogley"
EXIFDISCLAIMER="All rights reserved."
cd $DRIVEINITPATH/Screenshots
ln -s "$1"
echo "$1" > out-originalpath.txt
fn=$(basename "$1")
echo "$fn" > out-filename.txt
descn="$(osascript -e 'Tell application "System Events" to display dialog "Enter the description:" default answer "Screenshot of "' -e 'text returned of result' 2>/dev/null)"
$EXIFTOOLBIN -artist="$EXIFAUTHOR" -author="$EXIFAUTHOR" -copyright="$CURRYEAR $EXIFAUTHOR" -disclaimer="$EXIFDISCLAIMER" -comment="$descn" -description="$descn" "$fn"
$GOPATH/bin/drive push --quiet "$fn"
$GOPATH/bin/drive pub "$fn"
$GOPATH/bin/drive edit-desc --description "$descn" "$fn"
$GOPATH/bin/drive url "$fn" | grep -o 'http*.*' | pbcopy
# REMINDERS
# fn=`cat var.txt`
# you can install exiftool via brew
# capture on mac: cmd-shift-4
# change screenshot file type: defaults write com.apple.screencapture type png
# change screenshot file name: defaults write com.apple.screencapture name "JRC Screenshot"
# make changes take effect: killall SystemUIServer
@BishAU
Copy link

BishAU commented Aug 25, 2017

want to write me one?

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