Why a CLI for Dropbox on Mac OS X

I was thinking about a command-line interface (CLI) for Dropbox, and how I personally would take advantage of such a feature. So, after failing to find any indication that the Mac OS X Dropbox client contained a CLI, tonight on Twitter I made this comment:

Too bad the #Mac version of @Dropbox doesn’t have a CLI.

Shortly thereafter, I received this response:

@scott_lowe @Dropbox What would you do with it if you did?

I posted a response (which you can see if you follow either of the Twitter links above), but I realized that my response really needed a bit more background.

Like many people in IT today, I’m pretty mobile. I have a home office, but I also travel a fair amount. My laptop, a 2011 13″ MacBook Pro with 8GB of RAM and a 512GB SSD, is my primary computer. The problem is this: when I’m in my home office, I want my laptop to be configured a certain way, but when I’m traveling, I need it configured a different way. For example, when I’m in my home office, I want Synergy running so that I can connect to the Synergy server on my Mac Pro workstation. When I’m not in the home office, Synergy should not be running. So how do I get the computer to automatically reconfigure itself? The answer is quite simple, actually: an app called ControlPlane.

ControlPlane is a handy little application that performs a set of actions based on a context. A context is defined as a set of conditions, like (as in my situation) being connected to my 24″ Apple Cinema Display and being connected via Ethernet to a network using my home network’s IP addressing scheme. If all those conditions are met, then it’s quite likely I’m in my home office—meaning I’m in that particular context—and ControlPlane should perform a set of actions to reconfigure my laptop. Similarly, if those conditions aren’t true, then it’s quite likely I’m not in my home office—meaning I’m in a roaming or traveling context—and therefore my computer should be configured a different way. Handy, right?

To put some specifics on this idea, then, here’s how I use ControlPlane:

  • I have two contexts, one called Docked and one called Roaming. Docked is only for when I’m connected to my 24″ Apple Cinema Display in my actual home office, wired up via Ethernet (not wireless), and have an IP address off my home network’s subnet. When those conditions are true, I’m “docked” and I need Synergy running so that I can share keyboard and mouse between my Mac Pro workstation and my laptop.
  • Any other time, I’m not “docked” and should be in the Roaming context. In the Roaming context, Synergy should not be running.
  • When I enter the Docked context, ControlPlane should launch Synergy, if it’s not already running, and then issue a Growl notification that the computer is entering the Docked context.
  • When I leave the Docked context (meaning I’m entering the Roaming context), then ControlPlane should kill Synergy (if it’s running), and post a Growl notification.

ControlPlane is capable of much, much more, but (for now) this is sufficient. At some point in the future, I might have it mount network drives (or maybe my EncFS filesystem).

I said all that to finally come back to the comment that started all this: if Dropbox had a CLI (or AppleScript support, but that’s probably too much to ask for), then I could use ControlPlane to automate/manipulate the behavior of Dropbox as part of my contexts. For example, I could define another context—say, Disconnected—in which there are no active network interfaces. In that context, I’d like Dropbox to pause syncing. Then, when I enter another context, either Roaming or Docked, then Dropbox should continue syncing. However, without some sort of non-GUI access to Dropbox, this isn’t possible (to my knowledge).

Anyway, that’s what I was thinking. Courteous comments (or questions) are always invited and encouraged, so feel free to speak out below.

Tags: , , ,

  1. Mark Meulemans’s avatar

    Wow, not only is there no AppleScript dictionary for Dropbox or CLI functionality but the way it’s implemented leaves no room for basic OS X hacking to add this functionality.

    Unfortunately because the LSUIElement property in the Info.plist file for the app is set to YES it doesn’t show up in the Dock which means you can’t use AppleScript to activate the application. Manually setting this value to NO allows Dropbox to show up as an icon in the dock, but because they never intended this to operate that way they never implemented menus, even ones to pull up the preferences, so that was a complete bust.

    My second thought was to hack this functionality in using SIMBL. In the past I worked up a hack to Terminal.app using SIMBL to add bookmark functionality and automated logins, similar to SecureCRT, but no longer needed to once they released the Mac version. This solution would be dependent upon Dropbox being implemented on the Mac in Objective-C, but doing a class-dump on the executable shows its clearly written in something else. I was eventually able to find the bundle that Dropbox appears to use for its actual GUI elements, located at “/Library/DropboxHelperTools/Dropbox_u501/DropboxBundle.bundle”. I’d be curious to see if writing a SIMBL hack for Dropbox could be done against this bundle which could tie Dropbox into the Apple Event Manager to allow for this functionality to be added.

    My brain was starting to get fried so thanks for the post and giving me a nice 30-45 minute distraction from studying.

  2. shane d’s avatar

    There’s a CLI for the Linux version. Its a python script. Might be worth a look.

  3. Kenneth Ristau’s avatar

    I know some applications like TrueCrypt have a CLI onthe Mac. Tyipically, you can access this by invoking the binary from the command line (/Applications/TrueCrypt.app/MacOS/TrueCrypt -t -l, for example). I confirmed that Dropbox on my Mac does not provide this functionality.

    On my Linux systems dropbox does provide status and control options at the command line. You can start, stop, check status, toggle autostart, get the public url of a file, etc. There is no pause sync option, but that is effectively achieved by starting/stopping the service. The Linux version even provides a man page.

  4. Brandon’s avatar

    Why don’t you just kill Dropbox when you’re disconnected and restart it when you’re connected?

  5. Robert Pelletier’s avatar

    Disclaimer : I don’t use dropbox

    Is the service started via launchd? If so, launchctl unload /Path/To/DropBox.plist and launchctl load /Path/To/DropBox.plist should do the trick for you!

  6. Amit Patel’s avatar

    I too would like a CLI to control Dropbox syncing although I admit my setup is nowhere near as cool as yours.

  7. Ernie Oporto’s avatar

    While Dropbox will obviously stop syncing when there are no network connections, stopping and starting the sync at defined times would be helpful. Would be good if I could also do it for Skydrive, or Google Drive, too, in the case where the bandwidth gets too high and we need to throttle them to make the system usable.

  8. Jonathan’s avatar

    For those who want to show their support for a cli


  9. Nick’s avatar

    Why would you want to do the pausing of Dropbox yourself? The app already does, and quite well, and with few resources. When you disconnect from all networks, there is no path for it to sync. So it stops. If its on a LAN where another computer has the same Dropbox, it detects this and uses the LAN to sync. If you are on a wifi point, not same network, it syncs to the Dropbox cloud.

  10. Armand Welsh’s avatar

    For someone like me, that remotes into the mac via SSH, having a CLI would be extremely beneficial.

    My Mac hosts a media server on a limited access account. My primary user account is never logged into that Mac host with a GUI, as the mac is attached to a Television for watching shows, with the an application like Plex, or XBMC.

    I need to transfer a file from my iphone mail client’s attachments. so, I open the attachment in Dropbox, which syncs the fie to drop box. Now I want to ssh into my Mac to pull the file down to the mac. With a commandline tool, I wouldn’t need to sign in via a GUI client to make the last step of sending the file to my Mac, I could just Sync dropbox, and the file appears.

  11. dgw’s avatar

    @Jonathan: ALL my votes!

    Having CLI access to pause/resume sync based on time would really help me avoid having my machine disconnected from the network I’m using for much of the summer for “excessive” (“over a gigabyte” in an entire day is “excessive”) uploading. Both my Mac and PC laptops would benefit from this. To this idea, I say a hearty +1.

  12. Jon’s avatar

    @mb and others – that python script only works on Linux. It will not work with a Mac – as the original post is about.

  13. Michael’s avatar

    I wasted a better part of the day today trying to figure out how to get Dropbox to automatically start during Mac OS X (Mountain Lion) system boot, so I can sync my files without being logged in. I am stuck at an error message which seems to suggest that Dropbox is making assumption that the user is logged in via the GUI, which in my mind is so mind-bogglingly stupid that I just have no words. Obviously it works on Linux, so I fail to understand why the Mac OS X version would require a GUI.

    Anyway, my usage is that my home computer (Mac) serves web pages for family and friends and those web pages sit in Dropbox, and I frequently make updates from other computers that have Dropbox linked to the same account. But unless I am logged in, any changes I make don’t get synced to the home computer. And it isn’t practical for me to always be logged in because the computer is used by other people too, gets restarted at odd times, and can’t automatically log me in due to issues with kids being around to mess up things on the account.

  14. Armand’s avatar

    @Michael, I feel your pain. Myself I use the multiple logins feature of lion and mountain lion. I log into Dropbox with my account then I lock my session. The next user to log in knows to select the switch user option to login as themselves. Rather than fight it I decided to work with the way the system works because it’s only going to get worse with mavericks. OSX may be a power user’s dream OS but it is focused on the basic user that doesn’t use a CLI so it does make sense that the client stays within the same boundaries.

    I think it would make sense to provide either an API or some CLI utilities to control Dropbox on osx though, much like VLC and handbrake do so those of us that want a version that does not interact with the GUI can push replication when we want it.


Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>