Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Close Dropbox/GoogleDrive after syncing is finished?


  • Please log in to reply
9 replies to this topic
Roni787
  • Members
  • 224 posts
  • Last active: May 13 2015 07:21 AM
  • Joined: 04 Jun 2012

I have a backup program that is doing backups to my dropbox and google drive folders on my hard disk which sync the backup files respectively to my cloud google drive and dropbox accounts. But i don't want Dropbox and Google Drive to run constantly, only when a new backup is done. On my backup program i can setup a script that can be executed after a backup is finished and this script can start dropbox and google drive and they can start syncing the new backup.

But is it possible autohotkey script to detect when the syncing is finished and then to close the programs?



jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
For Dropbox:
Get Dropbox Status (Gist)
Get Dropbox Status (Gist Raw)
[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
Updated DropBox Script above
; 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

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

Roni787
  • Members
  • 224 posts
  • Last active: May 13 2015 07:21 AM
  • Joined: 04 Jun 2012

Can you tell me how to make the script to monitor if the dropbox status is up to date, i am not very advanced with ahk. If i put If in front of DropBoxStatus(Path) it gives error:

; 0 ==> Folder is not in Dropbox
; 1 ==> Up to Date
; 2 ==> Sync in Progress

MsgBox % DropBoxStatus("C:\Users\" A_UserName "\Dropbox")

If DropBoxStatus(Path)
{
    static RequestInfo := 0x3048302
    static ProcessId   := DllCall("kernel32.dll\GetCurrentProcessId")
    static ThreadId    := DllCall("kernel32.dll\GetCurrentThreadId")
    static RequestType := 1

    if !(DllCall("kernel32.dll\ProcessIdToSessionId", "UInt", ProcessId, "UInt*", SessionId))
        return "*" 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(path, &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 "*" DllCall("kernel32.dll\GetLastError")
    return StrGet(&BuffOut + 4, BytesRead - 5, "CP0")
}


jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
221 Posts and not ahk advanced? shocked.png

More like this:
Dropbox_Path := "C:\Users\USERNAME\Dropbox"    ; <== Change this to your DropBox Path

if (DropBoxStatus(Dropbox_Path) = 1)           ; <== if Status is 1 (explained above)
    MsgBox % "Dropbox is up to date"

; FUNCTIONS =====================================================================================================================

DropBoxStatus(Path, GetStatus := 0)
{
    static DropBoxStatus := {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 = 0)
        return GetStatus ? DropBoxStatus[99] : 99

    if !(DllCall("kernel32.dll\ProcessIdToSessionId", "UInt", ProcessId, "UInt*", SessionId))
        return "*" 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(path, &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 "*" DllCall("kernel32.dll\GetLastError")
    return GetStatus ? DropBoxStatus[StrGet(&BuffOut + 4, BytesRead - 5, "CP0")] : StrGet(&BuffOut + 4, BytesRead - 5, "CP0")
}

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

Roni787
  • Members
  • 224 posts
  • Last active: May 13 2015 07:21 AM
  • Joined: 04 Jun 2012

Thanks, now the script is working! Can it be modified and used for google drive?

 

221 Posts and not ahk advanced? shocked.png

 

 

I am mostly searching if there is already created scripts for what i need and i am trying with my limited knowledge to modify them to fit my needs. If i don't know something i ask. From there the post count.



jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012

Thanks, now the script is working! Can it be modified and used for google drive?


Nope. This function is just for Dropbox.
And since I dont use Google Drive I can not help you with it.
[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

Roni787
  • Members
  • 224 posts
  • Last active: May 13 2015 07:21 AM
  • Joined: 04 Jun 2012

Ok, no problem.

What is the best way to close Drobpox? I am using Process, Close, dropbox.exe and when it close the process the dropbox icon stay in the system tray, and if i move the mouse over it, it disappear.

#Persistent

Dropbox_Path := "E:\Dropbox"    ; <== Change this to your DropBox Path

SetTimer, Check, 100
gosub, Check

Check:

if (DropBoxStatus(Dropbox_Path) = 1)           ; <== if Status is 1 (explained above)
    ;MsgBox % "Dropbox is up to date"
     Process, Close, Dropbox.exe
	 
; FUNCTIONS =====================================================================================================================

DropBoxStatus(Path, GetStatus := 0)
{
    static DropBoxStatus := {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 = 0)
        return GetStatus ? DropBoxStatus[99] : 99

    if !(DllCall("kernel32.dll\ProcessIdToSessionId", "UInt", ProcessId, "UInt*", SessionId))
        return "*" 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(path, &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 "*" DllCall("kernel32.dll\GetLastError")
    return GetStatus ? DropBoxStatus[StrGet(&BuffOut + 4, BytesRead - 5, "CP0")] : StrGet(&BuffOut + 4, BytesRead - 5, "CP0")
}


jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012

when it close the process the dropbox icon stay in the system tray, and if i move the mouse over it, it disappear.

this is more a Windows problem

#Persistent

Dropbox_Path := "E:\Dropbox"    ; <== Change this to your DropBox Path

loop
{
    if (DropBoxStatus(Dropbox_Path) = 1)           ; <== if Status is 1 (explained above)
    {
        Process, Close, Dropbox.exe
        ExitApp
    }
    sleep 1000
}

; FUNCTIONS =====================================================================================================================

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

Roni787
  • Members
  • 224 posts
  • Last active: May 13 2015 07:21 AM
  • Joined: 04 Jun 2012

Ok, thanks!