Skip to content

Instantly share code, notes, and snippets.

@stansidel
Last active August 29, 2015 14:01
Show Gist options
  • Save stansidel/406293f495de14057635 to your computer and use it in GitHub Desktop.
Save stansidel/406293f495de14057635 to your computer and use it in GitHub Desktop.
Autostart Dropbox and Google Drive on a Mac OS X machine when an encrypted volume is mounted. Should work for Linux too

Dropbox and Google Drive autostart script

If you store your Dropbox and Google Drive folders on an encrypted drive it happens that the apps start before the volume is mounted on the system startup. Then you have to quit the app and run it again. This script aims to solve this problem.

The script is design for and tested on Mac OS X Mavericks. It should work on Linux too. For Windows solution look here.

Usage

  1. Create an app from this script (dropbox_autostart.sh) using Automator as described here. Save it in any folder under any name, e.g. as dropbox_autostart.app file under your Home folder.
  2. Change value of the volume variable in the script to your encrypted volume path.
  3. Turn off Dropbox and Google Drive autostart option (in Settings for each app).
  4. Open System Preferences - Users & Groups. Click on your username, then on "Login items". Click on the plus sign button (under the list) and choose the dropbox_autostart.app file, you've created in the Automator app earlier.
#!/bin/bash
# Change this variable to your encrypted volume path
volume="/Volumes/private_disk"
function run_app() {
number=$(ps aux | grep "$1.app" | wc -l)
if [ $number -gt 1 ]; then
echo "$1 is running"
else
echo "Starting $1"
open "/Applications/$1.app"
fi
}
count=0
for((;;))
do
if [ -d $volume ]; then
test $count -gt 0 && echo -en "\n"
run_app "Dropbox"
run_app "Google Drive"
break
else
((count+=2))
# See http://stackoverflow.com/questions/2388090/how-to-delete-and-replace-last-line-in-the-terminal-using-bash
echo -en "\rWaiting for volume $volume to be mounted: $count"
sleep 2s
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment