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: Automation, CLI, Macintosh, Storage
-
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.
-
There’s a CLI for the Linux version. Its a python script. Might be worth a look.
-
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.
-
Why don’t you just kill Dropbox when you’re disconnected and restart it when you’re connected?
-
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.
-
For those who want to show their support for a cli
-
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.
-
For someone like me, that remotes into the mac via SSH, having a CLI would be extremely beneficial.
Scenario:
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 comments
Comments feed for this article