Pastebin functionality from Dropbox and AutoHotKey

I’ve had another idea… press a certain key combination, and you get a link to whatever text you had selected. This mirrors the ability to easily share text on sites such as pastebin. To use it, you’ll need AutoHotKey and a Dropbox account. Then grab my updated AHK Dropbox library.

Usage

Download the file to wherever you keep the autohotkey file you usually run. Somewhere at the top of your script, be sure to have the following line:

#Include dropbox.ahk

Somewhere else in your script, include the following:

;; copy the selected text to a file in my dropbox
^#c::
	CopySelectionToDropbox()
Return

Be sure to update your user id in the library file; I haven’t discovered a way to glean that information from the system, sadly. The only way to get it is to copy a public link of something in your dropbox and extract the number from that.

You’re welcome to use your own keyboard shortcut for it, of course; ctrl+windows+c is pretty awkward to press. I’m thinking the scroll lock key probably be a pretty decent place to assign it. For the full AHK key list, see this help document. The code for the new function is after the break.

How it works

CopySelectionToDropbox()
{
	;; put selection onto clipboard
	Copy()
	
	;; get the location of the dropbox
	dropbox := GetDropboxFolderLocation()
	
	;; write the text to file in public folder
	filename = %A_Now%.txt
	FileAppend %clipboard%, %dropbox%\Public\%filename%
	
	;; get the public url of the last file copied
	user_id = 3771881			
	public_url := GetDropboxPublicURL(user_id, filename)
	
	;; replace clipboard with url to text
	clipboard = %public_url%
	
	TrayTip Dropbox, Put selection in dropbox as %filename%`n`nLink put onto clipboard
}

Andrew Guyton
http://www.disavian.net/

3 Comments

Cerberus

Wow, very nice library! I will tinker and play with this.

Jay Sheen

Can you give me an example of how to do this = “user id in the library file; I haven’t discovered a way to glean that information from the system, sadly. The only way to get it is to copy a public link of something in your dropbox and extract the number from that.”

Andrew Guyton

I was never able to figure out a way to extract that from the system via a program. However, it’s not hard to copy the public link generated by Dropbox (right-click the file, click dropbox, click “copy public link”) and put the number in that URL directly into your script. Here’s an example: http://dl.dropbox.com/u/#######/file.txt the ###### part is what I’m talking about.

Leave a Reply