Small DropBox Tip

rm
rms
Posts: 28
Joined: Sat Mar 02, 2013 9:32 am
Platform: Mac + iOS

Fri Aug 02, 2013 6:38 am Post

Seems like something that could be easy to do with the 3rd party Mac tool called "Keyboard Maestro". I can see where it's simple to look for "Launch" or "Quit", but it probably takes an Apple script to do the next step of telling Dropbox turn on or off "Pause". I can't get my head around Apple scripts. Perhaps someone can?

Me
Mex5150
Posts: 8
Joined: Sun Jun 30, 2013 12:37 am
Platform: Linux

Fri Aug 02, 2013 9:39 am Post

Hi All

Turns out the script was far easier than I though it would be:

Code: Select all

dropbox stop
scrivener
dropbox start
This works perfectly on Linux, and I don't see why it wouldn't on Windoze, I'm afraid you Mac guys are on your own thoug I know next to nothing about your OS LOL <sorry>

Anyway, to use the above just save it as a script and run that instead of starting Scrivener as you normally woud.

-Mex

Go
Gordon Robb
Posts: 51
Joined: Tue Nov 27, 2012 2:04 pm
Platform: Windows

Fri Aug 02, 2013 1:20 pm Post

OK, mister script guy :) I know you're stating this like it's an easy thing but...

what do you mean save this as a script and just run it? (Windows i'm talking about)

Ni
Niran
Posts: 73
Joined: Wed Jun 20, 2007 1:28 pm

Fri Aug 02, 2013 2:12 pm Post

I was looking for something elegant in keyboard maestro to pause Dropbox. But, you can not access Dropbox menus via keyboard maestro. However, using launching and quitting Scrivener as a trigger, keyboard maestro can stop and start Dropbox.

drpsync.jpg
Quit Dropbox
drpsync.jpg (24.92 KiB) Viewed 1557 times


drpstopsync.jpg
Re-launch Dropbox
drpstopsync.jpg (21.9 KiB) Viewed 1557 times

Me
Mex5150
Posts: 8
Joined: Sun Jun 30, 2013 12:37 am
Platform: Linux

Fri Aug 02, 2013 2:38 pm Post

Hi,
Gordon Robb wrote:OK, mister script guy :) I know you're stating this like it's an easy thing but...

what do you mean save this as a script and just run it? (Windows i'm talking about)

I don't have a windoze box here to try it on, but what you need to do is copy and past the above code into notepad and save it as a *.bat file. Double click it to run and is should work. If it doesn't try replacing the scrivener line with it's full path, it will probably be something like "C:Program Files/Scrivener/Scrivener.exe" If that doesn't work either give me a shout, and I'll set up a win virtual box to have a play and see if I can sort it out.

-Mex

User avatar
robertdguthrie
Posts: 3075
Joined: Mon Nov 09, 2009 10:06 pm
Platform: Mac
Location: St. Louis, MO, USA
Contact:

Fri Aug 02, 2013 4:09 pm Post

Mex5150 wrote:Hi All

Turns out the script was far easier than I though it would be:

Code: Select all

dropbox stop
scrivener
dropbox start
I'm afraid you Mac guys are on your own thoug I know next to nothing about your OS LOL <sorry>


Our OS LOL is very similar to your OS LOL; it's based on BSD instead of Linux, but Mac OS has a command line with Bash as the default shell. The only mods I would make is to use the "open" command as listed upstream for the reasons stated. The underlying Unix kernel and command line were the primary push for me to even try Mac OS LOL X. I felt right at home, but with more polished apps available to me. LOL
Often wrong, rarely in doubt.
Time for a change... I'm now rdale; same dog-avatar, same dog... channel?

js
jstovell
Posts: 22
Joined: Mon Apr 15, 2013 12:56 am
Platform: Mac

Wed Aug 21, 2013 9:51 am Post

For those who want something more robust than a Keyboard Maestro script, it is possible to make OS X take care of this for you automatically by using a launch agent. Using this method, it doesn't matter how you start Scrivener, and you don't need to remember to do anything special to manage DropBox at all. Instead, OS X will notice what you are doing and take care of everything for you.

To set this up, follow these three steps:

  1. Paste this into a plain text file:

    Code: Select all

    <?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>info.stovell.DropboxAutoStopForScrivener</string>
       <key>ProgramArguments</key>
       <array>
          <string>/bin/bash</string>
          <string>-c</string>
          <string>sleep 1; runningJobs=$(launchctl list); if [[ $runningJobs == *"com.literatureandlatte.scrivener2"* &amp;&amp; $runningJobs == *"com.getdropbox.dropbox"* ]]; then osascript -e "tell application id \"com.getdropbox.dropbox\" to quit"; touch /tmp/DropboxShouldStart_$UID; elif [[ $runningJobs != *"com.literatureandlatte.scrivener2"* &amp;&amp; $runningJobs != *"com.getdropbox.dropbox"* &amp;&amp; -e /tmp/DropboxShouldStart_$UID ]]; then open -b com.getdropbox.dropbox; rm /tmp/DropboxShouldStart_$UID; elif [[ $runningJobs == *"com.getdropbox.dropbox"* ]]; then rm /tmp/DropboxShouldStart_$UID; fi</string>
       </array>
       <key>WatchPaths</key>
       <array>
          <string>~/Library/Caches/com.literatureandlatte.scrivener2</string>
       </array>
    </dict>
    </plist>

  2. Save it in

    Code: Select all

    ~/Library/LaunchAgents
    with the name

    Code: Select all

    info.stovell.DropboxAutoStopForScrivener.plist

    • Make sure the file extension really is .plist, and not .plist.txt. (Sometimes TextEdit will add a hidden .txt file extension to plain text files.)
    • Be aware that

      Code: Select all

      ~
      stands for your user's home folder, which means that we are storing the file inside your user's own Library folder, not your computer's top level Library folder.
    • If your Mac is running OS X version 10.7 (Lion) or above, your user Library folder is hidden by default. You will need to follow the directions here in order to get access to your Library folder.
    • If there is no LaunchAgents folder in your Library folder already, simply create one and then put the file in it.
  3. Log out and log back in.
That's it. From now on, DropBox will quit as soon as you start Scrivener and will start again shortly after you quit Scrivener. :)

A couple of notes:
  1. If DropBox was not running when you started Scrivener, it will not start itself automatically after you quit Scrivener.
  2. You can manually start DropBox while Scrivener is running if you wish—but that would defeat the whole purpose of this, now wouldn't it?
If you change your mind, simply drag info.stovell.DropboxAutoStopForScrivener.plist to the Trash, and then log out. When you log back in, everything will be back to its default behaviour.
Last edited by jstovell on Wed Aug 28, 2013 6:00 pm, edited 1 time in total.

User avatar
AmberV
Posts: 23719
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Wed Aug 21, 2013 9:11 pm Post

Excellent tip, thanks for posting that!
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

js
jstovell
Posts: 22
Joined: Mon Apr 15, 2013 12:56 am
Platform: Mac

Thu Aug 22, 2013 12:05 am Post

Glad to. I'm always happy to find ways to procrastinate... er, to help others. :lol:

ma
marcoiac
Posts: 445
Joined: Mon Aug 29, 2011 12:12 am
Platform: Mac

Thu Aug 22, 2013 4:25 am Post

jstovell wrote:Glad to. I'm always happy to find ways to procrastinate... er, to help others. :lol:


Nice! Pro-sociality and procrastination going together. It does make sense, actually. Totally driven people are so absorbed by their own goals and plans that they hardly notice other people.

kd
kdbertel
Posts: 78
Joined: Mon Oct 25, 2010 10:20 pm
Platform: Windows

Sat Apr 05, 2014 8:28 pm Post

jstovell wrote:For those who want something more robust than a Keyboard Maestro script, it is possible to make OS X take care of this for you automatically by using a launch agent.


Thanks for this, though as stopping/starting Dropbox is a relatively heavy operation, I don't suppose there's any way of modifying this to simply pausing/unpausing it instead?