Help: Call batch file from button

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
mikes16
Posts: 59
Joined: 02 Mar 2007 16:18

Help: Call batch file from button

Post 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

jupe
Posts: 3292
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Help: Call batch file from button

Post by jupe »

As explained in the scripting help file, indent multi line scripts by at least 1 space per line, 1st line is optional.

klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Help: Call batch file from button

Post 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

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Help: Call batch file from button

Post by highend »

You are aware that you could call python with the script just from the XY script without the intermediate .bat file call?
One of my scripts helped you out? Please donate via Paypal

mikes16
Posts: 59
Joined: 02 Mar 2007 16:18

Re: Help: Call batch file from button

Post by mikes16 »

Thank you both for your replies.

WirlyWirly
Posts: 263
Joined: 21 Oct 2020 23:33
Location: Win 10 @ 100% (3440x1440)

Re: Help: Call batch file from button

Post 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')

Post Reply