Page 1 of 1

Locate a Dropbox?

Posted: 18 Aug 2017, 09:51
by MaxAstro
Is there any reliable way to, assuming you know that Dropbox is installed on the computer the script is being run on, determine the location of the Dropbox folder or otherwise reference it as a variable? I'm using Dropbox to sync some files my script relies on between several computers, and that works, but currently I have to tell everyone to put their Dropbox in the same location and I'm wondering if there is a better way to find my files.

Re: Locate a Dropbox?

Posted: 18 Aug 2017, 10:38
by BoBo
What about to check on your system if dropbox has set an entry about that folder in the registry?

Re: Locate a Dropbox?

Posted: 18 Aug 2017, 10:39
by sttrebo
this one works for me

; dropbox path
foundPos := RegExMatch(A_ScriptDir, "i)dropbox")
pos := foundpos + 6
Path := SubStr(A_ScriptDir, 1, pos)
;

also i found this one previously, but needs a bit of work (doesn't work on all my systems)

MsgBox % DropBoxFolder()
return

DropBoxFolder(){
RegRead, OutputVar, HKEY_CURRENT_USER , Software\Dropbox , InstallPath
FileRead, OutputVar, % RegExReplace(OutputVar,"bin$") "info.json"
RegExMatch(OutputVar, "path"": ""\K[^""]+", DropBoxFolder)
StringReplace, DropBoxFolder, DropBoxFolder, \\, \, all
IniDelete, %A_Temp%\DropBox_Location.ini, location
IniWrite, %DropBoxFolder%, %A_Temp%\DropBox_Location.ini, location
return DropBoxFolder
}

Re: Locate a Dropbox?

Posted: 18 Aug 2017, 10:54
by MaxAstro
That registry one looks promising... The first one won't work for me because in at least one case I need to reference the Dropbox, but the script needs to not be in the Dropbox. Thanks for the ideas!

Re: Locate a Dropbox?  Topic is solved

Posted: 18 Aug 2017, 11:04
by sttrebo
just need to find then parse the info.json file correctly (i like this method better than the ones above)

https://www.dropbox.com/help/desktop-we ... lder-paths

Re: Locate a Dropbox?

Posted: 18 Aug 2017, 11:27
by MaxAstro
Thank you! That is perfect; I even already have code for parsing JSON objects.

Re: Locate a Dropbox?

Posted: 18 Aug 2017, 11:42
by sttrebo
can you share that code? i'm playing around with the same thing.

Re: Locate a Dropbox?

Posted: 18 Aug 2017, 12:49
by MaxAstro
I'm actually having some trouble with it because of how the JSON object is formatted - namely that it's an object, each key of which has the value of another JSON object. I'm having a hard time retrieving the "nested" JSON object.

Re: Locate a Dropbox?

Posted: 18 Aug 2017, 13:02
by MaxAstro
Update: Got it working, if a bit messily since it partially parses by hand. This code relies on the AHK JSON library which can be found here: https://autohotkey.com/boards/viewtopic.php?t=627

Code: Select all

^m::
	MsgBox % GetDropBoxPath()
	return

GetDropBoxPath(Business := false, DesiredField := "path")	; Pass "true" to get the path of a business install
{							; DesiredField can also be "host", "is_team", or "subscription_type" to read other data
	EnvGet, AppLocal, LOCALAPPDATA
	if FileExist(A_AppData . "\Dropbox\info.json")
		FileToRead := A_AppData . "\Dropbox\info.json"
	else if FileExist(AppLocal . "\Dropbox\info.json")
		FileToRead := AppLocal . "\Dropbox\info.json"
	FileRead, JsonString, % FileToRead
	Pos := InStr(JsonString, (Business ? "business" : "personal"))
	JsonString := SubStr(JsonString, Pos)
	Pos := InStr(JsonString, "{")
	JsonString := SubStr(JsonString, Pos)
	Pos := InStr(JsonString, "}")
	JsonString := SubStr(JsonString, 1, Pos)
	DBObj := {}
	DBObj := JSON.Load(JsonString)
	return DBObj[DesiredField]
}

Re: Locate a Dropbox?

Posted: 18 Aug 2017, 20:28
by sttrebo
a bit more manual but short and sweet:

Code: Select all

EnvGet, appdata_Loc, LOCALAPPDATA
FileRead, string, %appdata_Loc%\DropBox\info.json
Path_Loc := (InStr(string, "path", false)) + 8
Host_Loc := (InStr(string, "host", false)) - 4
Path_Len := Host_Loc - Path_Loc
Db_Path := StrReplace(SubStr(string, Path_Loc, Path_Len), "\\", "\")
msgbox, DropBox path is: %Db_Path%

Re: Locate a Dropbox?

Posted: 19 Aug 2017, 09:07
by jNizM