Locate a Dropbox? Topic is solved
Locate a Dropbox?
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?
What about to check on your system if dropbox has set an entry about that folder in the registry?
Re: Locate a Dropbox?
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
}
; 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?
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
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
https://www.dropbox.com/help/desktop-we ... lder-paths
Re: Locate a Dropbox?
Thank you! That is perfect; I even already have code for parsing JSON objects.
Re: Locate a Dropbox?
can you share that code? i'm playing around with the same thing.
Re: Locate a Dropbox?
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?
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?
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?
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile