Locate a Dropbox? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Locate a Dropbox?

18 Aug 2017, 09:51

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.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Locate a Dropbox?

18 Aug 2017, 10:38

What about to check on your system if dropbox has set an entry about that folder in the registry?
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: Locate a Dropbox?

18 Aug 2017, 10:39

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
}
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: Locate a Dropbox?

18 Aug 2017, 10:54

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!
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: Locate a Dropbox?  Topic is solved

18 Aug 2017, 11:04

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
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: Locate a Dropbox?

18 Aug 2017, 11:27

Thank you! That is perfect; I even already have code for parsing JSON objects.
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: Locate a Dropbox?

18 Aug 2017, 11:42

can you share that code? i'm playing around with the same thing.
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: Locate a Dropbox?

18 Aug 2017, 12:49

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.
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: Locate a Dropbox?

18 Aug 2017, 13:02

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]
}
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: Locate a Dropbox?

18 Aug 2017, 20:28

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%

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Google [Bot], Nerafius and 84 guests