Page 1 of 1

Help: Call batch file from button

Posted: 15 Jul 2025 10:51
by mikes16
Hi - I am trying to call a batch file from a button. It works - but it is a but strange for me - I click the button and the script is partially displayed, and then I click the first line of the script and my script executes.

Is this the expected behavior or am I doing something wrong? THis is the script I am trying to call - and I would like to JUST click the button and have it execute:

The XYPLORER script int he Left Click section of the button:

Code: Select all

//S
if (<curpath> == "C:\MyStorage\Wallpapers") {
  run """C:\Users\xxx\AppData\Roaming\espanso\scripts\run_filenames.bat""";
} else {
  status "This button only works in C:\MyStorage\Wallpapers", "8B0000", "white";
}

THe batch script:

Code: Select all

@echo off
REM Batch file to delete duplicate images and rename remaining ones.

setlocal

set SCRIPT=C:\Users\xxx\AppData\Roaming\espanso\scripts\filedups.py
set PYTHON=C:\Python312\python.exe

echo Running duplicate remover and renamer...
%PYTHON% "%SCRIPT%" "%CD%"

echo.
echo Done. Window will close in 5 seconds...
timeout /t 5 > nul

endlocal

Re: Help: Call batch file from button

Posted: 15 Jul 2025 11:04
by jupe
As explained in the scripting help file, indent multi line scripts by at least 1 space per line, 1st line is optional.

Re: Help: Call batch file from button

Posted: 15 Jul 2025 11:07
by klownboy
In Xyplorer scripts all lines must be indented at least one space. Of course there are exceptions. Your "if" line doesn't appear to be indented.

Edit: jupe beat me to the punch

Re: Help: Call batch file from button

Posted: 15 Jul 2025 11:59
by highend
You are aware that you could call python with the script just from the XY script without the intermediate .bat file call?

Re: Help: Call batch file from button

Posted: 15 Jul 2025 14:25
by mikes16
Thank you both for your replies.

Re: Help: Call batch file from button

Posted: 15 Jul 2025 19:03
by WirlyWirly
As highend mentioned, you don't need a middle-man .bat file, it's quite simple to call a python script using XY's built-in scripting language. Refer to the help file for the use of run, lax(), and the variable <selitems> which can be quite useful.

Code: Select all

run lax("C:\Path\to\python.exe" "C:\path\to\script.py" <selitems>)
    ...
    echo('Done')