V1: Reload script when Dropbox finishes syncing

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
RandomBoy
Posts: 4
Joined: 18 Apr 2024, 11:04

V1: Reload script when Dropbox finishes syncing

18 Apr 2024, 11:20

I have been using this function for over 2 years, and it has worked flawlessly. A couple of days ago, on both my computers this stopped working... It simply wouldn't Get the Dropbox sync status no more. Here's the code below, and here are some threads where the same code was mentioned (here and here ). Is there anything that I can do?

Code: Select all


; Return Values
; 0  [NOT_IN_DROPBOX]   ==>  Folder is not in Dropbox
; 1  [UP_TO_DATE]       ==>  Up to Date
; 2  [SYNCHRONIZING]    ==>  Sync in Progress
; 99 [NOT_RUNNING]      ==>  Dropbox is not running


MsgBox % GetDropboxStatus("C:\Users\" A_UserName "\Dropbox")     ; ==> return e.g. 1
MsgBox % GetDropboxStatus("C:\Users\" A_UserName "\Dropbox", 1)  ; ==> return e.g. UP_TO_DATE ;

GetDropboxStatus(DBLocation, StatusToText := 0)
{
    static DBStatusTxt   := {0: "NOT_IN_DROPBOX", 1: "UP_TO_DATE", 2: "SYNCHRONIZING", 99 : "NOT_RUNNING"}
    static RequestInfo   := 0x3048302
    static ProcessId     := DllCall("kernel32.dll\GetCurrentProcessId")
    static ThreadId      := DllCall("kernel32.dll\GetCurrentThreadId")
    static RequestType   := 1

    Process, Exist, % "Dropbox.exe"
    if !(ErrorLevel)
        return StatusToText ? DBStatusTxt[99] : 99

    if !(DllCall("kernel32.dll\ProcessIdToSessionId", "UInt", ProcessId, "UInt*", SessionId))
        return "*ProcessIdToSessionId [" DllCall("kernel32.dll\GetLastError") "]"
    PipeName := "\\.\pipe\DropboxPipe_" SessionId

    SizeIn := VarSetCapacity(BuffIn, 16 + 524)
    , NumPut(RequestInfo, BuffIn, 0, "Int"), NumPut(ProcessId, BuffIn, 4, "Int")
    , NumPut(ThreadId, BuffIn, 8, "Int"), NumPut(RequestType, BuffIn, 12, "Int")
    , StrPut(DBLocation, &BuffIn + 16, 524//2, "UTF-16")

    SizeOut := VarSetCapacity(BuffOut, 16382, 0)
    if !(DllCall("kernel32.dll\CallNamedPipe", "Str", PipeName, "Ptr", &BuffIn, "UInt", SizeIn, "Ptr", &BuffOut, "UInt", SizeOut, "UInt*", BytesRead, "UInt", 1000))
        return "*CallNamedPipe [" DllCall("kernel32.dll\GetLastError") "]"
    return StatusToText ? DBStatusTxt[StrGet(&BuffOut + 4, BytesRead - 5, "CP0")] : StrGet(&BuffOut + 4, BytesRead - 5, "CP0")
}

This was a really handy function, as I had all my scripts on a DropBox folder, which was obviously synced across my two workstations... So when I'd update a script, DropBox would then start syncing and once the sync was over the GetDropboxStatus function will notice it, and I had it set so that my master script would then be refreshed after every sync. It was a great auto-refresh script that would also refresh when editing the #include files.
User avatar
Chunjee
Posts: 1454
Joined: 18 Apr 2014, 19:05
Contact:

Re: V1: Reload script when Dropbox finishes syncing

18 Apr 2024, 15:20

One other idea is you can reload when a change is detected and static for over {{x}} seconds. It sounds like there may be more than one file involved in the sync. If not you can just reload after any file change is detected.
RandomBoy
Posts: 4
Joined: 18 Apr 2024, 11:04

Re: V1: Reload script when Dropbox finishes syncing

18 Apr 2024, 16:24

Chunjee wrote: One other idea is you can reload when a change is detected and static for over {{x}} seconds. It sounds like there may be more than one file involved in the sync. If not you can just reload after any file change is detected.

That sounds it may work. Any resource link, or useful searchable keywords that you could kindly point out, please?
RandomBoy
Posts: 4
Joined: 18 Apr 2024, 11:04

Re: V1: Reload script when Dropbox finishes syncing

19 Apr 2024, 08:28

After further testing and debugging, I have now realized that the script:
  • Detects when Dropbox is syncing and outputs "2" "SYNCING" message box as it should
  • If I add the wrong folder as a folder path, it will output "0" "NOT_IN_DROPBOX"
  • And also if I close Dropbox, it will correctly output "99" "NOT_RUNNING"
It looks like the script is broken only when Dropbox is up-to-date. When Dropbox is up-to-date, the script will output a message box containing "9" and then some blank text. Instead of "1" "UP_TO_DATE".
"9" shouldn't even be an option, I guess?

Code: Select all

static DBStatusTxt   := {0: "NOT_IN_DROPBOX", 1: "UP_TO_DATE", 2: "SYNCHRONIZING", 99 : "NOT_RUNNING"}
RandomBoy
Posts: 4
Joined: 18 Apr 2024, 11:04

Re: V1: Reload script when Dropbox finishes syncing

19 Apr 2024, 10:08

I could get this working with a quirk.
Because of the script now wrongly outputting "9" for UP_TO_DATE, instead of "1" as it should, I have changed the remaining part of my code accordingly, and it seems to be working fine. Obviously, this is not ideal, and I wish for someone to step in and guide me to permanently fix this... or hopefully the next Dropbox update will solve it?

Anyhow... in case someone is interested, I am posting below the rest of the code that combined with the snippet at the beginning allow you to reload an AHK master script every single time Dropbox finishes synchronising. If you have a spare Dropbox account, and you only keep your AHK scripts on it (like I do), this works a treat, and it will reload all your AHK scripts every time you press "save" on the notepad.
This worked steadily for over two years until a few days ago... but the way it is revised right now, it's also working.

Code: Select all

#Persistent
Dropbox_Path := "C:\Dropbox"    ; <== Change this to your DropBox Path
loop
	{
    if (DropBoxStatus(Dropbox_Path) = 2) ; is Dropbox Syncing?
		{
		loop
			{
			if (DropBoxStatus(Dropbox_Path) = 9) ; Did Dropbox finish its Syncing?  <===== This is the bit I had to change to "9", It should be "1", but after the last DB update I had issues, revert to 1 if it starts to not work
				{
				ReLoadAllScripts()
				}
			sleep 1000
			}
		}
	sleep 1000
	}
;;;;;;;;;;;;;;;;;;;;; Reload After DropBox finishes Syncing - END

;;;;;;;;;;;;;;;;;;;;; Kill and ReLoad All scripts - START
ReLoadAllScripts()
{
	AHKPanic(1,0,0,0) ;Kill all AutoHotKey Script (excluding the ones running as admin)
	Sleep 1000
	Run, C:\Dropbox\AHK\MASTER_SCRIPT.ahk ; Add your master Script path here
	ReLoad
	}
;;;;;;;;;;;;;;;;;;;;; Kill and ReLoad All scripts - END


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AHK PANIC Function
; Source Here: https://www.reddit.com/r/AutoHotkey/comments/mfrfrb/a_script_to_close_other_scripts/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

AHKPanic(Kill=0, Pause=0, Suspend=0, SelfToo=0) {
DetectHiddenWindows, On
WinGet, IDList ,List, ahk_class AutoHotkey
Loop %IDList%
  {
  ID:=IDList%A_Index%
  WinGetTitle, ATitle, ahk_id %ID%
  IfNotInString, ATitle, %A_ScriptFullPath%
    {
    If Suspend
      PostMessage, 0x111, 65305,,, ahk_id %ID%  ; Suspend. 
    If Pause
      PostMessage, 0x111, 65306,,, ahk_id %ID%  ; Pause.
    If Kill
      WinClose, ahk_id %ID% ;kill
    }
  }
If SelfToo
  {
  If Suspend
    Suspend, Toggle  ; Suspend. 
  If Pause
    Pause, Toggle, 1  ; Pause.
  If Kill
    ExitApp
  }
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: feiy and 183 guests