Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A cross-platform text Clipboard using Dropbox Network
This hint describes how to set up a cross-platform text-only clipboard using Dropbox.

I've found myself frequently having a piece of text in one computer and wanting to have it in another one. I use Dropbox all the time, so the 'easiest' was to save the text to a text file in the Dropbox folder and open it in the other computer. Hey, it's like a Dropbox Clipboard!

See, the thing I haven't mentioned is that the two machines in question are a MacBook and a Windows 7 box, so that leaves out any Mac- or Windows-only solution. I also want something simple (so Synergy is out too) and tweakable. Full clipboard support is not simple, but fortunately I just need plain text and AppleScript (for OS X) and AutoHotkey (for Windows) can do everything I'll need, so let's code a bit.

One of AutoHotkey's strengths is its complete keyboard control so it can do it all in one punch:
;
; AutoHotkey Version: AutoHotkey_L 1.1 (Unicode)
; Language:           English
; Platform:           Win7 SP1
; Author:             Antonio Bueno 
; Last Mod:           2011-06-19
;
; Script Function:
;  - Copies (and cuts) to and pastes from a file in Dropbox, using Shift+Ctrl+C, X and V
;  - All the operations are in plain text (and encoded using UTF-8)
;  - The main objective is to get a plain-text clipboard across several computers
;  - As a side effect it works as a system-wide "paste without format" function
;  - In Windows Explorer, copying files results in a filelist with full paths

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases
SendMode Input ; Recommended for new scripts due to its superior speed and reliability
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory

Menu, Tray, Icon, %A_WinDir%\system32\shell32.dll, 217 ; Shows a clipboard icon in the system tray
; NOTE: The clipboard icon index is different for each Windows version

FileEncoding, UTF-8-RAW ; Text file operations use UTF-8 encoding without BOM

; Hardcoded location of Dropbox folder (proper method requires sqlite3 queries or base64 decoding)
DropboxFolder = %A_MyDocuments%\My Dropbox

; Shift+Ctrl+c copies (and Shift+Ctrl+x cuts) to DropboxClipboard.txt
+^c::
+^x::
  FileDelete, %DropboxFolder%\DropboxClipboard.txt
  ClipBoard =
  StringRight CopyOrCut, A_ThisHotKey, 1
  Send ^%CopyOrCut%
  ClipWait 2
  If !ErrorLevel
    FileAppend, %ClipBoard%, %DropboxFolder%\DropboxClipboard.txt
Return

; Shift+Ctrl+v pastes from DropboxClipboard.txt
+^v::
  IfExist, %DropboxFolder%\DropboxClipboard.txt
    FileRead, ClipBoard, %DropboxFolder%\DropboxClipboard.txt
  Else
    ClipBoard =
  Send ^v
  Sleep 50
Return
As the comments in the script mention, not only do I get a clipboard across all my Dropbox-linked computers, but I also get a system-wide 'paste without format' function.

NOTE: The script above requires a Unicode build of AutoHotkey_L. If you don't want to install it just to test this, just download the binaries and drop the script on the .exe.

AppleScript has no problems with the clipboard, but does not handle the keyboard shortcuts. I solved it with FastScripts, associating the keys Shift+Command+C, Shift+Command+X, and Shift+Command+V to these three scripts below.

Copy:
-- Hardcoded location of Dropbox folder (proper method requires sqlite3 or base64 decoding)
set DropboxFolder to ((path to home folder) as string) & "Dropbox"
set DropboxClipboard to DropboxFolder & ":DropboxClipboard.txt" as string

tell application "System Events"
  keystroke "c" using command down
end tell
try
  set outFile to open for access DropboxClipboard with write permission
  set eof outFile to 0
  write (the clipboard as «class utf8») to outFile
  close access outFile
on error
  close access outFile
end try
Cut:
-- Hardcoded location of Dropbox folder (proper method requires sqlite3 or base64 decoding)
set DropboxFolder to ((path to home folder) as string) & "Dropbox"
set DropboxClipboard to DropboxFolder & ":DropboxClipboard.txt" as string

tell application "System Events"
  keystroke "x" using command down
end tell
try
  set outFile to open for access DropboxClipboard with write permission
  set eof outFile to 0
  write (the clipboard as «class utf8») to outFile
  close access outFile
on error
  close access outFile
end try
Paste:
-- Hardcoded location of Dropbox folder (proper method requires sqlite3 or base64 decoding)
set DropboxFolder to ((path to home folder) as string) & "Dropbox"
set DropboxClipboard to DropboxFolder & ":DropboxClipboard.txt" as string

try
  set inFile to open for access DropboxClipboard
  set the clipboard to (read inFile)
  close access inFile
on error
  close access inFile
end try
tell application "System Events"
  keystroke "v" using command down
end tell
NOTE: For these scripts to work you probably need to 'Enable access for assistive devices' in the Universal Access System Preference pane.

This is a standalone and simplified version of the scripts I really use, for the sake of clarity. The ones I use get the Dropbox folder path from Dropbox's configuration files, encrypts and decrypts the text in the file, and do a couple of extra things with files inside the Dropbox folder, all this accompanied with notifications, so I know what's happening.

I hope someone else find this useful, and if there are better ways to do it, please tell about it in the comments.

P.S. I really, really would love to have something similar in my iPhone. Right now I get by giving DropboxClipboard.txt a star in the Dropbox app and using the system clipboard, but it's not the same.

[crarko adds: I haven't tested this one.]
    •    
  • Currently 3.80 / 5
  You rated: 4 / 5 (5 votes cast)
 
[7,268 views]  

A cross-platform text Clipboard using Dropbox | 11 comments | Create New Account
Click here to return to the 'A cross-platform text Clipboard using Dropbox' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A cross-platform text Clipboard using Dropbox
Authored by: willgonz on Jun 30, '11 08:14:50AM

How do you make Dropbox sync on a Mac? I dropped some files while on one computer and I had to go to the other computer and sync. I want it to sync without me being in front of the computer. I have some Folder Actions setup for my Dropbox folder.



[ Reply to This | # ]
A cross-platform text Clipboard using Dropbox
Authored by: everkleer80 on Jul 01, '11 08:50:36AM

The sync should occur automatically. In fact I don't know of any way to manually sync. I'm sorry if this is a stupid question, but you do know this refers to the Dropbox app (www.dropbox.com) and not the Mac OS X dropbox, right?



[ Reply to This | # ]
A cross-platform text Clipboard using Dropbox
Authored by: atnbueno on Jul 01, '11 10:57:37AM
William, currently I don't have problems with userless sync, even when using computers in different networks. Are you using the current Dropbox version (1.1.35)?

[ Reply to This | # ]
so, what problem is this solving?
Authored by: Seth Milliken on Jun 30, '11 10:18:09AM

It would help if the author of this hint better articulated the problem he's really trying to solve. As described here, the goals and requirements are inconsistent, making it difficult to gauge the circumstances under which this hint might actually be of use.

But in any case, if you consider this Rube Goldberg contraption simple compared to Synergy—which just works for vanilla text clipboard sync once you have it configured—you're doing it wrong.



[ Reply to This | # ]
so, what problem is this solving?
Authored by: atnbueno on Jul 01, '11 11:06:29AM

Perhaps I should have been more terse with the ingredients (as in "AutoHotkey in Windows, FastScripts in OS X and Dropbox in both") but I think the first sentence is quite clear about the goal, and I wanted to illustrate where the idea had come from. Also, FastScripts is not the only program that allows you to define keyboard shortcuts in OS X.

I discarded Synergy not because I have anything against it (in fact I think it's an amazing piece of software) but because using another client/server just for a shared clipboard seemed too much, specially when I already had one (Dropbox) that allowed me to avoid setting up configurations, permissions, firewall exceptions, ... and also, don't forget, I wanted it tweakable.

I think it's a question of starting points: I regularly use AutoHotkey in Windows, and Dropbox everywhere. And Applescript comes with OS X. A total of 3.25 KiB (almost half of that being comments) is not a Rube Goldberg contraption (I had to look what was that :-D).



[ Reply to This | # ]
A cross-platform text Clipboard using Dropbox
Authored by: marksch on Jun 30, '11 02:59:17PM
My solution for this problem is Clipboard Link.
http://clipboardlink.economy-x-talk.com

Works on Mac, Windows and Linux (pretty much cross-platform).
---
Mark

Economy-x-Talk
Have your own custom software created
http://economy-x-talk.com


[ Reply to This | # ]
A cross-platform text Clipboard using Dropbox
Authored by: atnbueno on Jul 01, '11 11:15:15AM

Hey, very nice. I didn't find your program when I looked into possibilities. I'm trying in now and I'll have some feedback for you soon.



[ Reply to This | # ]
A cross-platform text Clipboard using Dropbox
Authored by: r00tabega on Jun 30, '11 05:14:09PM

Not sure about others, but when I use LogMeIn or Microsoft Remote Desktop Connection or VNC to access one machine or another, I can easily cut/paste between the two.

Also sending a skype message to a dummy account will synchronize text easily between machines without using a remote windowing solution.

For large blocks of text I want to preserve, Google Notebook still works and meets my needs.



[ Reply to This | # ]
A cross-platform text Clipboard using Dropbox
Authored by: atnbueno on Jul 01, '11 11:27:02AM

Ha, I've used the IM idea in the past. The VNC et al. ideas fall again (for me) in the "too complicated for just a clipboard" category.



[ Reply to This | # ]
A cross-platform text Clipboard using Dropbox
Authored by: everkleer80 on Jul 01, '11 09:02:38AM

This is a neat little hint, and I'm surprised there's not already an iPhone app to do this. If I had more time on my hands, and an iPhone, I'd probably write one.

As mentioned in one of the comments, Synergy is quite easy to set up. On Windows it's quite easy, and on the Mac it's a piece of cake if you get SynergyKM which, if I remember correctly, includes a GUI and installer for Synergy. However, Synergy may be overkill if all you want to do is keep your clipboard in sync, but if you use multiple computers side-by-side then it's a must-have!



[ Reply to This | # ]
A cross-platform text Clipboard using Dropbox
Authored by: atnbueno on Jul 01, '11 11:29:58AM
That's what I meant about discarding Synergy just for clipboard syncing. And man I would love to know enough to do it in iOS.

[ Reply to This | # ]