Explorer copy to Dropbox via AutoHotKey v2

Sorry for a new version so soon, but I realized somewhat belatedly that the easy way to get a file’s location is to simply copy it, something that AutoHotKey does rather easily. So, I’ve put a new version of the library up.

This one can copy multiple files/folders to the dropbox, whereas my previous version was only limited to just one. Once I copy, I loop through, check if each is a file or folder, and act accordingly. I’m pretty happy with the change; usage and code after the break.

To use it, you’ll need AutoHotKey and a Dropbox account.

Usage (copied from last post)

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:

#IfWinActive ahk_class CabinetWClass
	;; copy the current file to the dropbox
	^+d::
		CopySelectedFileOrFolderToDropbox()
	Return
#IfWinActive

How it works

CopySelectedFileOrFolderToDropbox()
{
	;; get the location of the dropbox
	dropbox := GetDropboxFolderLocation()
	
	;; get the selected files by copying them from the clipboard
	Copy()
	
	;; init the tray message
	traymsg =
	lastfile =
	
	;; parse through it
	Loop parse, clipboard, `n, `r
    {
		;; split the path
		SplitPath A_LoopField, filename
		
		;; find out if this file is a directory
		FileGetAttrib attr, %A_LoopField%
		
		if ( ErrorLevel > 0 )
		{
			traymsg = %traymsg%Failed to copy %A_LoopField% to Dropbox\Public\`n`n
		}
		IfInString attr, D
		{
			FileCopyDir %A_LoopField%, %dropbox%\Public\%filename%\
			traymsg = %traymsg%Copied %filename% to Dropbox\Public\%filename%\`n`n
		}
		else
		{
			FileCopy %A_LoopField%, %dropbox%\Public\
			traymsg = %traymsg%Copied %filename% to Dropbox\Public\`n`n
		}
		
		lastfile = %filename%
    }

	;; get the public url of the last file copied
	user_id = 3771881			
	public_url := GetDropboxPublicURL(user_id, lastfile)

	;; put the url on the clipboard
	clipboard = %url%
	
	;; add that to the tray msg
	traymsg = %traymsg%Put url to %lastfile% on clipboard
	
	;; show the tray msg
	TrayTip Dropbox, %traymsg%
}

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

Leave a Reply