Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

1 hour ago, Muggins said:

Hi folks,

I launch RPCS3 Lightgun games via AHK scripts so no emulator is selected in Launchbox.

I can exit the games using a button on the Lightgun (When offscreen) and pressing escape on the keyboard but would also like them to exit and the script terminate in the same way when pressing Buttons 12 + 1 on my cabinet as do my other games.

Currently when I press Buttons 12 + 1 the emulator closes but the script does not complete / terminate, leaving AHK and the Lightgun software running.

Would anyone know of a method to get Launchbox to send the escape key using this method please?

Can you share what your script(s) looks like?  Also, is Button 12+1 what you have mapped in LaunchBox to Exit Game (in Tools - Options - Game Controllers - Mappings)?

  • Thanks 1
Link to comment
Share on other sites

5 hours ago, JoeViking245 said:

Can you share what your script(s) looks like?  Also, is Button 12+1 what you have mapped in LaunchBox to Exit Game (in Tools - Options - Game Controllers - Mappings)?

Hi, yes it says Button 12 + Button 1 in the Exit Game button mapping.

This is the script...

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance Force

SetWorkingDir C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun

Process, Exist, Lightgun.exe
If (!ErrorLevel = 0) {
Process,Close,Lightgun.exe
sleep, 1000
}
Run, C:\Utils\Sinden Lightguns\Mouse Mode - RPCS3\Lightgun.exe
 
Run, C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\rpcs3.exe C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\games\BCES01070\PS3_GAME\USRDIR\timecrisis4.self --config "C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\config\custom_configs\config_BCES01070_tc4_2p.yml"

sleep, 1000
Run, C:\Utils\NoMousy\NoMousy.exe /hide	;Hides mouse cursor with NoMousy

;Start Button
$MButton::
send {LButton down}
sleep, 60
send {MButton down}
sleep, 20
send {MButton up}
sleep, 60
send {LButton up}
Return

$Esc::
Process,Close,Lightgun.exe
Process,Close,rpcs3.exe
Run,taskkill /im "rpcs3.exe" /F
Run, C:\Utils\NoMousy\NoMousy.exe		;Restores mouse cursor
sleep, 500
ExitApp
Return

 

Link to comment
Share on other sites

6 hours ago, Muggins said:

Hi, yes it says Button 12 + Button 1 in the Exit Game button mapping.

When you press the button combo 12+1, you need to press (and hold) 12 then 1. You can still do it real fast, it just needs to be "done in order".  If it's more ergonomic to do 1 then 12, swap Joy1 and Joy12 (keeping "1" in front of the first "joy" as shown).

 

Not tested, but looks really good 'on paper'. :D

#SingleInstance Force
SetWorkingDir C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun

Process, Exist, Lightgun.exe
If (!ErrorLevel = 0) {
  Process,Close,Lightgun.exe
  Sleep, 1000
}

Run, C:\Utils\Sinden Lightguns\Mouse Mode - RPCS3\Lightgun.exe
Run, C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\rpcs3.exe C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\games\BCES01070\PS3_GAME\USRDIR\timecrisis4.self --config "C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\config\custom_configs\config_BCES01070_tc4_2p.yml"
Sleep, 1000
Run, C:\Utils\NoMousy\NoMousy.exe /hide	;Hides mouse cursor with NoMousy

;Start Button
$MButton::
{
  send {LButton down}
  sleep, 60
  send {MButton down}
  sleep, 20
  send {MButton up}
  sleep, 60
  send {LButton up}
}

;Press Joy12 then Joy1
1Joy1::
{
   If GetKeyState("Joy12")
      ExitRoutine()
}

$Esc::ExitRoutine()

ExitRoutine()
{	
  Process,Close,Lightgun.exe
  Process,Close,rpcs3.exe
  Run,taskkill /im "rpcs3.exe" /F
  Run, C:\Utils\NoMousy\NoMousy.exe		;Restores mouse cursor
  Sleep, 500
  ExitApp
}

 

  • Thanks 1
Link to comment
Share on other sites

3 hours ago, JoeViking245 said:

When you press the button combo 12+1, you need to press (and hold) 12 then 1. You can still do it real fast, it just needs to be "done in order".  If it's more ergonomic to do 1 then 12, swap Joy1 and Joy12 (keeping "1" in front of the first "joy" as shown).

 

Not tested, but looks really good 'on paper'. :D

#SingleInstance Force
SetWorkingDir C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun

Process, Exist, Lightgun.exe
If (!ErrorLevel = 0) {
  Process,Close,Lightgun.exe
  Sleep, 1000
}

Run, C:\Utils\Sinden Lightguns\Mouse Mode - RPCS3\Lightgun.exe
Run, C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\rpcs3.exe C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\games\BCES01070\PS3_GAME\USRDIR\timecrisis4.self --config "C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\config\custom_configs\config_BCES01070_tc4_2p.yml"
Sleep, 1000
Run, C:\Utils\NoMousy\NoMousy.exe /hide	;Hides mouse cursor with NoMousy

;Start Button
$MButton::
{
  send {LButton down}
  sleep, 60
  send {MButton down}
  sleep, 20
  send {MButton up}
  sleep, 60
  send {LButton up}
}

;Press Joy12 then Joy1
1Joy1::
{
   If GetKeyState("Joy12")
      ExitRoutine()
}

$Esc::ExitRoutine()

ExitRoutine()
{	
  Process,Close,Lightgun.exe
  Process,Close,rpcs3.exe
  Run,taskkill /im "rpcs3.exe" /F
  Run, C:\Utils\NoMousy\NoMousy.exe		;Restores mouse cursor
  Sleep, 500
  ExitApp
}

 

Tried that thanks but it doesn't seem to do anything different to the previous one, is there a way to see what is going on with the script?

Link to comment
Share on other sites

1 hour ago, Muggins said:

Tried that thanks but it doesn't seem to do anything different to the previous one, is there a way to see what is going on with the script?

Because of how AHK reads one button and then the other, LaunchBox's Exit Game might intercept the combo-press 1st. 

You said the script and the Lightgun software are still running when pressing the [LB] button combo (and I assume the mouse wasn't restored also), but not when shooting offscreen or pressing Escape.  I assume the latter are triggering the escape hotkey sequence (and those 2 methods still worked with the 'new' code that uses the ExitRoutine() method). 

 

Take 2:  Essentially what's happening, if the emulator is closed via the Exit Game button combo, the script (still running) will 'see' that the emulator isn't running [any more] and jump to ExitRoutine().  Hopefully resolving the issue.  

#SingleInstance Force
SetWorkingDir C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun

Process, Exist, Lightgun.exe
If (!ErrorLevel = 0) {
  Process,Close,Lightgun.exe
  Sleep, 1000
}

Run, C:\Utils\Sinden Lightguns\Mouse Mode - RPCS3\Lightgun.exe
Run, C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\rpcs3.exe C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\games\BCES01070\PS3_GAME\USRDIR\timecrisis4.self --config "C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\config\custom_configs\config_BCES01070_tc4_2p.yml"
Sleep, 1000
Run, C:\Utils\NoMousy\NoMousy.exe /hide	;Hides mouse cursor with NoMousy

Process, WaitClose, rpcs3.exe
ExitRoutine()

;Start Button
$MButton::
{
  send {LButton down}
  sleep, 60
  send {MButton down}
  sleep, 20
  send {MButton up}
  sleep, 60
  send {LButton up}
}

$Esc::ExitRoutine()

ExitRoutine()
{	
  Process,Close,Lightgun.exe
  Process,Close,rpcs3.exe
  Run,taskkill /im "rpcs3.exe" /F
  Run, C:\Utils\NoMousy\NoMousy.exe		;Restores mouse cursor
  Sleep, 500
  ExitApp
}

 

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, JoeViking245 said:

Because of how AHK reads one button and then the other, LaunchBox's Exit Game might intercept the combo-press 1st. 

You said the script and the Lightgun software are still running when pressing the [LB] button combo (and I assume the mouse wasn't restored also), but not when shooting offscreen or pressing Escape.  I assume the latter are triggering the escape hotkey sequence (and those 2 methods still worked with the 'new' code that uses the ExitRoutine() method). 

 

Take 2:  Essentially what's happening, if the emulator is closed via the Exit Game button combo, the script (still running) will 'see' that the emulator isn't running [any more] and jump to ExitRoutine().  Hopefully resolving the issue.  

#SingleInstance Force
SetWorkingDir C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun

Process, Exist, Lightgun.exe
If (!ErrorLevel = 0) {
  Process,Close,Lightgun.exe
  Sleep, 1000
}

Run, C:\Utils\Sinden Lightguns\Mouse Mode - RPCS3\Lightgun.exe
Run, C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\rpcs3.exe C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\games\BCES01070\PS3_GAME\USRDIR\timecrisis4.self --config "C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun_2Player\config\custom_configs\config_BCES01070_tc4_2p.yml"
Sleep, 1000
Run, C:\Utils\NoMousy\NoMousy.exe /hide	;Hides mouse cursor with NoMousy

Process, WaitClose, rpcs3.exe
ExitRoutine()

;Start Button
$MButton::
{
  send {LButton down}
  sleep, 60
  send {MButton down}
  sleep, 20
  send {MButton up}
  sleep, 60
  send {LButton up}
}

$Esc::ExitRoutine()

ExitRoutine()
{	
  Process,Close,Lightgun.exe
  Process,Close,rpcs3.exe
  Run,taskkill /im "rpcs3.exe" /F
  Run, C:\Utils\NoMousy\NoMousy.exe		;Restores mouse cursor
  Sleep, 500
  ExitApp
}

 

Tried that thanks, now when I press the front left on my Sinden light gun the whole thing closes as if I had pressed the escape key, that button is mapped as the middle mouse button in the Sinden software.

Sorry, I am being a pain!

Link to comment
Share on other sites

4 hours ago, Muggins said:

is there a way to see what is going on with the script?

when any AHK script is running there should be a tray icon visible. double click on it to bring up a window, it will default to showing all the most recent lines executed by the script. it's very useful for troubleshooting.

 

 

 

33 minutes ago, Muggins said:

Tried that thanks, now when I press the front left on my Sinden light gun the whole thing closes as if I had pressed the escape key, that button is mapped as the middle mouse button in the Sinden software.

Sorry, I am being a pain!

Seems the Return got removed so it is triggering the Esc hotkey / ExitRoutine when you execute the MButton hotkey.

 

So change it to this, just adding Return after all of it

;Start Button
$MButton::
{
  send {LButton down}
  sleep, 60
  send {MButton down}
  sleep, 20
  send {MButton up}
  sleep, 60
  send {LButton up}
}
Return

 

  • Thanks 1
Link to comment
Share on other sites

25 minutes ago, skizzosjt said:

when any AHK script is running there should be a tray icon visible. double click on it to bring up a window, it will default to showing all the most recent lines executed by the script. it's very useful for troubleshooting.

 

 

 

Seems the Return got removed so it is triggering the Esc hotkey / ExitRoutine when you execute the MButton hotkey.

 

So change it to this, just adding Return after all of it

;Start Button
$MButton::
{
  send {LButton down}
  sleep, 60
  send {MButton down}
  sleep, 20
  send {MButton up}
  sleep, 60
  send {LButton up}
}
Return

 

That now works great thank you both! I can exit and close the script using either the Button 12 + 1 combo or offscreen right on the dpad.

Here is the working script just in case it helps anyone else...

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance Force

SetWorkingDir C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun

Process, Exist, Lightgun.exe
If (!ErrorLevel = 0) {
Process,Close,Lightgun.exe
sleep, 1000
}
Run, C:\Utils\Sinden Lightguns\Mouse Mode - RPCS3\Lightgun.exe
 
Run, C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun\rpcs3.exe C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun\games\BCES01070\PS3_GAME\USRDIR\razingstorm.self --config "C:\Utils\LaunchBox\Emulators\RPCS3_Lightgun\config\custom_configs\config_BCES01070_tcrs.yml", ,Hide

sleep, 1000
Run, C:\Utils\NoMousy\NoMousy.exe /hide	;Hides mouse cursor with NoMousy

Process, WaitClose, rpcs3.exe
ExitRoutine()

;Start Button
$MButton::
{
  send {LButton down}
  sleep, 60
  send {MButton down}
  sleep, 20
  send {MButton up}
  sleep, 60
  send {LButton up}
}
Return

$Esc::ExitRoutine()

ExitRoutine()
{	
  Process,Close,Lightgun.exe
  Process,Close,rpcs3.exe
  Run,taskkill /im "rpcs3.exe" /F
  Run, C:\Utils\NoMousy\NoMousy.exe		;Restores mouse cursor
  Sleep, 500
  ExitApp
}

 

  • Like 1
  • Game On 1
Link to comment
Share on other sites

  • 1 month later...

Hello everyone,

I need your help. I created a copy of Retroarch that I use to play lightgun games. To do this, the Sinden software must be started in parallel. I would like to implement this via an autohotkey script so that when I start a game, the Sinden software starts first and then after a few seconds Retroarch. When I close the game, I want the Sinden Software to close as well. Can someone help me?

Link to comment
Share on other sites

On 8/3/2024 at 9:40 AM, Pineappleking said:

Hello everyone,

I need your help. I created a copy of Retroarch that I use to play lightgun games. To do this, the Sinden software must be started in parallel. I would like to implement this via an autohotkey script so that when I start a game, the Sinden software starts first and then after a few seconds Retroarch. When I close the game, I want the Sinden Software to close as well. Can someone help me?

 

I would use additional applications for launching the Sinden software and enable checkbox for Run Before Main Application. This is just an example. Script will need to run the Sinden software, wait for Retoarch to exist, then not exist, at that point it will close the Sinden Software

Run, X:\path\to\sinden\software\sinden.exe
WinWait, ahk_exe retroarch.exe
WinWaitClose, ahk_exe retroarch.exe
WinClose, ahk_exe sinden.exe

 

If it stays open I would change the WinClose line to this

Process, Close, sinden.exe
  • Thanks 1
Link to comment
Share on other sites

15 hours ago, skizzosjt said:

 

I would use additional applications for launching the Sinden software and enable checkbox for Run Before Main Application. This is just an example. Script will need to run the Sinden software, wait for Retoarch to exist, then not exist, at that point it will close the Sinden Software

Run, X:\path\to\sinden\software\sinden.exe
WinWait, ahk_exe retroarch.exe
WinWaitClose, ahk_exe retroarch.exe
WinClose, ahk_exe sinden.exe

 

If it stays open I would change the WinClose line to this

Process, Close, sinden.exe

PERFECT! It works. Thank you, thank you, thank you :)

  • Game On 1
Link to comment
Share on other sites

  • 3 weeks later...

AHK script to sync saves between different emulators

Hi everyone,

I need to sync save files between three instances of Duckstation: Duckstation Standalone, Duckstation Lightgun Edition, and Retroarch (with the dedicated core). I know it's possible to configure a single save folder, and I've already done this for the two standalone versions of Duckstation. However, for Retroarch, I’d prefer to keep the current setup because the save folder contains files from many other emulators and games, and I don't want to create any confusion.

So, I'm looking for a script that syncs .mcd files by updating them based on the most recent modification date, without touching any other files or folders. I’ve tried a script suggested by ChatGPT, and it seems to work perfectly,  but I’d like to get confirmation from someone more experienced to ensure that this solution is safe and reliable.

I set up Duckstation standalone as the default retroarch save method and that is : separate memorycard for each game (title)

Additionally, I plan to use similar script to sync saves between Switch emulators like Sudachi, Ryujinx, and the old Yuzu.

I’m already familiar with software like FreeFileSync and Syncthing, which I use to sync MAME saves and records between two computers in different locations. However, this time I need a solution that only runs when I launch the game and doesn't stay in memory. I think an AHK script that runs before launching the game might be the ideal solution. Do you think I should insert it either before the game starts or at the exit? maybe yes.

 

Give me your opinion

Thanks a lot for your help!

 

Script

 

; Set the two folders
sourceFolder := "C:\Path\Duckstation\Memcards"
targetFolder := "D:\Path\Retroarch\Saves"

; Loop through all .mcd files in the source folder
Loop, Files, %sourceFolder%\*.mcd, F
{
    ; Get the name of the current file (without the path)
    fileName := A_LoopFileName

    ; Get the full path of the file in the target folder
    targetFile := targetFolder "\" fileName

    ; If the file already exists in the target folder, compare modification dates
    if (FileExist(targetFile))
    {
        ; Get the modification date of the source and target files
        FileGetTime, sourceTime, %A_LoopFileFullPath%, M
        FileGetTime, targetTime, %targetFile%, M

        ; If the file in the source folder is more recent, copy it to the target folder
        if (sourceTime > targetTime)
        {
            FileCopy, %A_LoopFileFullPath%, %targetFile%, 1
        }
    }
    else
    {
        ; If the file does not exist in the target folder, copy it
        FileCopy, %A_LoopFileFullPath%, %targetFile%
    }
}

; Loop through all .mcd files in the target folder
Loop, Files, %targetFolder%\*.mcd, F
{
    ; Get the name of the current file (without the path)
    fileName := A_LoopFileName

    ; Get the full path of the file in the source folder
    sourceFile := sourceFolder "\" fileName

    ; If the file already exists in the source folder, compare modification dates
    if (FileExist(sourceFile))
    {
        ; Get the modification date of the target and source files
        FileGetTime, targetTime, %A_LoopFileFullPath%, M
        FileGetTime, sourceTime, %sourceFile%, M

        ; If the file in the target folder is more recent, copy it to the source folder
        if (targetTime > sourceTime)
        {
            FileCopy, %A_LoopFileFullPath%, %sourceFile%, 1
        }
    }
    else
    {
        ; If the file does not exist in the source folder, copy it
        FileCopy, %A_LoopFileFullPath%, %sourceFile%
    }
}

 

 

Edited by Sbaby
Link to comment
Share on other sites

On 8/24/2024 at 1:04 PM, Sbaby said:

I think an AHK script that runs before launching the game might be the ideal solution. Do you think I should insert it either before the game starts or at the exit?

My thoughts...

Looks good Chat-thingy. :)  The only far-fetched issue could be if the 'newer' save file was corrupt (for whatever reason).  But most likely, it's not likely.

At 1st I was thinking have it run after the game exits because of the processing time (i.e. the game would load faster if it wasn't waiting for this to complete).  But realistically, the time it takes to do this is probably next-to-nothing (assuming you don't have a bazillion save states).  So run it before (as you figured) so you're sure you're loading the most recent save.  Also, make sure to have Wait checked in the Additional App. This way the game won't try to load simultaneously with the script still running.

Link to comment
Share on other sites

4 hours ago, JoeViking245 said:

My thoughts...

Looks good Chat-thingy. :)  The only far-fetched issue could be if the 'newer' save file was corrupt (for whatever reason).  But most likely, it's not likely.

At 1st I was thinking have it run after the game exits because of the processing time (i.e. the game would load faster if it wasn't waiting for this to complete).  But realistically, the time it takes to do this is probably next-to-nothing (assuming you don't have a bazillion save states).  So run it before (as you figured) so you're sure you're loading the most recent save.  Also, make sure to have Wait checked in the Additional App. This way the game won't try to load simultaneously with the script still running.

Thank you for the feedback on my script; it was really helpful. You've made me consider the remote possibility of file corruption, which could lead to the deletion of both game saves. Although I regularly perform backups, I'm thinking about adding a function at the start of the script that creates a backup in a zip file for all the MCD files in both folders. What do you think? This way, if the game fails to load the save, I can immediately investigate and see what happened, still having the possibility to recover at least one of the correct saves, since each would be stored in a different zip file. Hopefully, at least one of the two would be intact.

Link to comment
Share on other sites

2 minutes ago, Sbaby said:

Thank you for the feedback on my script; it was really helpful. You've made me consider the remote possibility of file corruption, which could lead to the deletion of both game saves. Although I regularly perform backups, I'm thinking about adding a function at the start of the script that creates a backup in a zip file for all the MCD files in both folders. What do you think? This way, if the game fails to load the save, I can immediately investigate and see what happened, still having the possibility to recover at least one of the correct saves, since each would be stored in a different zip file. Hopefully, at least one of the two would be intact.

Ya, probably a good idea.

One way to go about this:

Create a folder to store the backups (/backup saves/)

  • zip all the Save files (folders?).
  • Add a date timestamp to the zip's filename.  (similar to how LB saves its Backup files) This creates unique filenames.
    • "Backup 2023-08-26 13-17-43.7z"
  • Save the zip to your above folder
  • TO KEEP THINGS FROM GETTING OUT OF CONTROL...
  • Count the number of files in the [above] saves folder
    • if 'count' is greater than 5
    • delete the oldest file
  • aka keep only the 5 most recent files
Link to comment
Share on other sites

3 hours ago, JoeViking245 said:

Ya, probably a good idea.

One way to go about this:

Create a folder to store the backups (/backup saves/)

  • zip all the Save files (folders?).
  • Add a date timestamp to the zip's filename.  (similar to how LB saves its Backup files) This creates unique filenames.
    • "Backup 2023-08-26 13-17-43.7z"
  • Save the zip to your above folder
  • TO KEEP THINGS FROM GETTING OUT OF CONTROL...
  • Count the number of files in the [above] saves folder
    • if 'count' is greater than 5
    • delete the oldest file
  • aka keep only the 5 most recent files

thanks nice idea, i will try it and then tell you ☺️

  • Like 1
Link to comment
Share on other sites

On 8/26/2024 at 11:04 PM, JoeViking245 said:

Ya, probably a good idea.

One way to go about this:

Create a folder to store the backups (/backup saves/)

  • zip all the Save files (folders?).
  • Add a date timestamp to the zip's filename.  (similar to how LB saves its Backup files) This creates unique filenames.
    • "Backup 2023-08-26 13-17-43.7z"
  • Save the zip to your above folder
  • TO KEEP THINGS FROM GETTING OUT OF CONTROL...
  • Count the number of files in the [above] saves folder
    • if 'count' is greater than 5
    • delete the oldest file
  • aka keep only the 5 most recent files

with which command line do i create the zipper with autohotkey ? can't find it

Link to comment
Share on other sites

6 minutes ago, Sbaby said:

with which command line do i create the zipper with autohotkey ? can't find it

It doesn't have one built-in.  Probably just run the one that's with LB already.

Run, "D:\LaunchBox\ThirdParty\7-Zip\7z.exe" a "<path/to/Mysaves.7z>" "<path\to\files\to\add>"

 

Link to comment
Share on other sites

ok great thanks, this new script that adds the backup would seem to work, what do you think?

 

Script

 

;;---------------"Automatic Synchronization + MCD File Backup Between Two Folders"---------------

; Full path to 7z.exe, if necessary
sevenZip := "M:\Giochi\Utility\Launchbox\ThirdParty\7-Zip\7z.exe"

; Set the main folders and backup folders
sourceFolder1 := "C:\\temp\\prova sync\\1"
backupFolder1 := "C:\\temp\\prova sync\\1\\_backup"

sourceFolder2 := "C:\\temp\\prova sync\\2"
backupFolder2 := "C:\\temp\\prova sync\\2\\_backup"

; Create backup folders if they do not exist
FileCreateDir, %backupFolder1%
FileCreateDir, %backupFolder2%

; Generate a timestamp for the backup file names
FormatTime, timestamp, , yyyy-MM-dd HH-mm-ss

; Create backup of .mcd files in the first folder
backupFile1 := backupFolder1 "\Backup_MCD_" timestamp ".zip"
RunWait, % sevenZip " a -tzip """ backupFile1 """ """ sourceFolder1 "\*.mcd"""

; Create backup of .mcd files in the second folder
backupFile2 := backupFolder2 "\Backup_MCD_" timestamp ".zip"
RunWait, % sevenZip " a -tzip """ backupFile2 """ """ sourceFolder2 "\*.mcd"""

; Keep only the last 5 backups in the first folder
LimitBackupFiles(backupFolder1, 5)

; Keep only the last 5 backups in the second folder
LimitBackupFiles(backupFolder2, 5)

; Function to limit backup files to a maximum number
LimitBackupFiles(folder, maxFiles) {
    FileList := []
    Loop, Files, %folder%\*.zip
    {
        FileList.Push({Name: A_LoopFileFullPath, Time: A_LoopFileTimeCreated})
    }
    FileList.Sort("Time")
    Loop, % FileList.MaxIndex() - maxFiles
    {
        FileDelete, % FileList[A_Index].Name
    }
}

; Loop through all .mcd files in the source folder
Loop, Files, %sourceFolder1%\*.mcd, F
{
    ; Get the name of the current file (without the path)
    fileName := A_LoopFileName

    ; Get the full path of the file in the target folder
    targetFile := sourceFolder2 "\" fileName

    ; If the file already exists in the target folder, compare modification dates
    if (FileExist(targetFile))
    {
        ; Get the modification date of the source and target files
        FileGetTime, sourceTime, %A_LoopFileFullPath%, M
        FileGetTime, targetTime, %targetFile%, M

        ; If the file in the source folder is more recent, copy it to the target folder
        if (sourceTime > targetTime)
        {
            FileCopy, %A_LoopFileFullPath%, %targetFile%, 1
        }
    }
    else
    {
        ; If the file does not exist in the target folder, copy it
        FileCopy, %A_LoopFileFullPath%, %targetFile%
    }
}

 

 

 

 

 

Description :

Path to 7z.exe: Make sure the path is correct. If 7z.exe is not in the system PATH, you must specify the full path.

Backup folder creation: The script automatically creates backup folders if they do not already exist.

Synchronization and backup: .mcd files are synchronized and compressed into time-stamped zipper archives. Only the last 5 backup files are kept to avoid filling too much space.

Link to comment
Share on other sites

I recently discovered that, due to a mouse movement error, I accidentally set my AutoHotkey scripts to open with a different autohotkey.exe on my system. As a result, I noticed that many of my scripts weren't working as expected. I had never checked which version of AutoHotkey was set as default on my Windows, so I tested various versions and finally found that the correct path I was probably using is \Autohotkey\UX\AutoHotkeyUX.exe.

Does this mean that most of the scripts I've shared might not have worked correctly for anyone unless they were using AutoHotkeyUX? 😅 With the UX version, everything seems to be working fine. I'm wondering if it's normal for Windows to default to that specific path and if I should continue using this version to ensure my scripts work correctly.

Thanks in advance for your advice!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...