プログラムを一時停止して一度に 1 つずつ同期させたいインスタンスを制御して、相互に干渉しないようにする方法はありますが、一時停止、再開、または状態を確認するにはどうすればよいですか。
ドロップボックス API をざっと調べたところ、主にアップロード、ダウンロードなどを行うことができるように見えますが、ドロップボックス インスタンスを実際に制御したり、自分で同期するプログラムを作成したりするにはどうすればよいですか?
Python または C++ でこれを行うことができます
The Dropbox API is the way you interact with the service from your own client, not the way you automate their desktop client app (the thing that integrates into Finder/Explorer/etc.).
It's probably not impossible to write your own client to replace their client, or maybe even to write a client that coexists with theirs (where you'd leave theirs permanently set to "Pause Syncing", and yours would only handle the sync side of things… although you'd lose the benefit of automatically triggered syncs whenever the local store changes, and instead have to poll for changes or set up a parallel filesystem watch). Since the API is built around web services, C++ is a pretty bad choice for the language, especially since there are pre-built wrappers for Python.
But anyway, I'm pretty sure this is not what you want to do. What you want is just to control the normal desktop client, and tell it when to pause or resume syncing, right?
The web API (and the SDKs that wrap it) can't possibly help you with that. You have to automate the client app, by using the appropriate tools for your platform. And, since the client doesn't have an automation control interface, you have to do it by automating the GUI.
Mac OS X has a high-level way to do this through System Events UI Scripting, which you can access from Python via ScriptingBridge
or appscript
, or C++ via… well, just don't. Windows only has a lower-level way to do this, by synthesizing WM_*
messages by hand, which you can do from Python via pywin32
or from C++ via the native Win32 API.
However, either way, it's going to be a pain. For example, the simplest Python appscript
solution would probably look something like this (untested):
sysev = appscript.app('System Events')
dropbox = sysev.application_processes['Dropbox']
menu = dropbox.menu_bars[1].menu_bar_items[-1].menus[1]
item = menu.items['Pause Syncing']
item.click()
The Windows equivalent would be even messier, involving sending a WM_*
message to get a menu, pulling apart the structure, etc.
It's much easier to use a higher-level GUI automation tool. Mac OS X comes with Automator built in. Create a workflow, click Record, pull down the Dropbox menu, click the "Pause Syncing" item, click Stop, and you're done. Actions is probably the most similar tool for windows, but there are dozens of other options, like AutoIt, which may be better.
So, having created an Automator action or an AutoIt script, how do you trigger than from Python or C++? Well, you probably don't need to. You've already got something you can double-click or run from the shell. If you want to wrap it up in Python, you can, e.g., via the subprocess
module (with the open
command on Mac, with shell=True
on Windows).
Meanwhile, keep in mind that modern versions of OS X and Windows don't let apps take control of each other willy-nilly. On OS X, you'll have to "Enable access for assistive devices" in the Accessibility pane of System Preferences; on Windows… it changes with each new release, and I don't keep up.