前回のバックアップ以降に VS Code が使用されているかフォーカスされている場合に限り、15 分ごとにフォルダーを増分バックアップする方法を見つけようとしています。
これを実現する方法について誰かアイデアを持っていますか?
答え1
AutoHotkey で実行するのは比較的簡単です... これまで使用したことがない場合は、構文の強調表示機能を備えた SciTE4AutoHotkey も入手することをお勧めします。
同様のことを行うための大まかな概要は次のとおりです。ウィンドウ タイトルが適切に機能するようにコードをデバッグする必要があります (トレイ アイコンの Window Spy 機能を使用して、VS Code に適切な WinTitle を取得します。ヘルプの説明については、を参照してくださいWinTitle
)。また、バックアップを実行するには、run ステートメントをデバッグする必要があります。バックアップは直接実行することも、バッチ ファイルとして実行することもできますが、バッチ ファイルの方が簡単な場合もあります。
; Global variable to store last active window time
Global gLastActive
; This will call the Backup() function periodically..
SetTimer, Backup, % 15*60*1000 ; 15 minutes, in milliseconds
; This is the main loop, just sets a global if the window is active at any point
Loop {
If WinActive("VS Code") { ; this will need to be a valid WinTitle
gLastActive := A_TickCount
; MsgBox % "Window detected..." ; debug message for getting WinTitle correct
}
Sleep 1000
}
ExitApp ; Denote logical end of program, will never execute
; Backup function will run periodically and only back things up
; if VS Code was active since last time...
Backup() {
Static lastTick
; If the window was active after the last backup, run a backup this time
If (gLastActive>lastTick)
Run, C:\Target.cmd, C:\WorkingDir, Hide ; this will need to be corrected for syntax
lastTick := A_TickCount
}
注記:これは完全にテストされていないコードであり、試してみるためのフレームワークの例を提供しているだけです。