Batch Scripting + AutoHotKey

Get help with using AutoHotkey and its commands and hotkeys
AndrewUD
Posts: 2
Joined: 28 May 2020, 04:53
Facebook: https://www.facebook.com/andrea.colussi

Batch Scripting + AutoHotKey

28 May 2020, 05:07

Dear All,
I Googled around for a solution to this subject, but I didn't found a simple reply.
I have written a bunch of Batch (.bat) scripts that I successfully used over the years on both Win7 and Win10 OS.
Now I start using the AutoHotKey scripting to keep advance of its valuable features but wanted to integrate my old Batch scripts inside the AutoHotKey.
Since I intend to have the Batch code executed at first (the batch requested also some input from the user and then create something... folders/files), and at the end of the script, I would like to continue using the same AutoHotKey script which launched the Batch code... I dunno how to put together the 2 worlds, therefore I wanna ask you for help.

(1) I post here below a quick example of the batch script which collected a data from the user, creates a specific folder, open up the created folder

Code: Select all

@ECHO OFF
REM *******************************************
REM CREAZIONE/LINK DIRETTO CARTELLE AOV x TECNICO
REM Release 1.0 - 2020-05-28 (aColussi)
REM *******************************************

SET date=%date%
	SET year=%date:~6,4%

:INPUT_AOV
   CLS
   ECHO.
   COLOR 0E
   ECHO.CREAZIONE CARTELLA AOVyy-XXXX x TECNICO
   ECHO.---------------------------------------
   ECHO.Author: [email protected]
   ECHO.v1.1  
   ECHO.
   ECHO.
   ECHO.
   SET /p I.AOV=Inserire AOVyy-XXXX (COMPLETO):
   SET i.aov.anno=%I.AOV:~3,2%
   SET anno.compl=20%i.aov.anno%
   MD "E:\P\DocTecCom\%anno.compl%\%I.AOV%"
   ECHO.
   ECHO.*********************************************
   ECHO.CREAZIONE CARTELLA COMPLETATA CON SUCCESSO...
   ECHO.*********************************************
   ECHO.
   EXPLORER "E:\P\DocTecCom\%anno.compl%\%I.AOV%"
 

(2) then I would like to continue using AutoHotKey to clipboard-save the folder address

Code: Select all

^!z::
clipboard := ""
Send , ^{f4}{esc}^c
return

(3) something I would like now to do, having an Acrobat PDF open, to use the above clipboard to write it in the SaveAs PDF window and go on saving the file in the just created folder I have done above.
Code still to be written for this part of the AutoHotKey script


The Batch works like a charm and I'd like to continue using batch scripting, but I dunno if I can put it directly on the AutoHotKey script or if I have to recall the .bat file and use any delay/pause in the AutoHotkey script.

Thanks to all of you who could give me any suggestions.
I'm sorry if this is something already asked before.


Andrew (Italy)
garry
Posts: 2295
Joined: 22 Dec 2013, 12:50

Re: Batch Scripting + AutoHotKey

28 May 2020, 06:55

don't know how batch works but maybe can try this

Code: Select all

;SET /p I.AOV=Inserire AOVyy-XXXX (COMPLETO):
;   SET i.aov.anno=%I.AOV:~3,2%
;   SET anno.compl=20%i.aov.anno%
;-E:\P\DocTecCom\%anno.compl%\%I.AOV%
;--------------------------------------
stringmid,anno_compl,a_now,1,4
stringmid,i_aov,a_now,1,8
fd=E:\P\DocTecCom\%anno_compl%\%I_AOV%
;msgbox,%fd%
;return
ifnotexist,%fd%
 filecreatedir,%fd%
try
 {
 setworkingdir,%fd%
 run,%fd%
 run,%comspec% /k         ;- DOS for test
 }
catch
 msgbox,NOT FOUND=%fd%
exitapp
AndrewUD
Posts: 2
Joined: 28 May 2020, 04:53
Facebook: https://www.facebook.com/andrea.colussi

Re: Batch Scripting + AutoHotKey

28 May 2020, 08:21

Thank you Garry for the prompt reply.
Actually I'd like to keep the .bat file and scripting codes, since I need to use others files I've written in the past.
Working on the script I found a solution which worked and that open the .bat file, wait for its completion (close the cmd at the end) and then continue with normal AutoHotkey scripting.
This is what I used, no matter what the .bat file does, it's interesting the rest of the AutoHotkey code. I had to use several "Sleep" commands to let the time to execute and store the input correctly, otherwise it missed some Clipboard copying along the script.

Code: Select all

^+o::
runwait %comspec% /c "P:\Home_Users\acolussi\DATI\AutoHotKey Scripting\Creazione Cartelle AOV x TECNICO R1.1.bat" ;run in wait to complete mode the .bat file
Sleep 1000  ; wait 1 second
clipboard := "" ; clear Clipboard
Send ^{f4}{esc}^c ; copy window/folder address of the new created folder
Sleep 1000 ; wait a bit to let the address bar to be correctly highlighted, otherwise the clipboard would be blank
indirizzo := clipboard ; pass the clipboard folder address to variable
Send !{Esc} ;ALT+ESC go back to Acrobat window where we started the AutoHotKey script from
StringRight aovn, indirizzo, 10 ;extract the 10 chars on the right side of text string
Clipboard = %aovn%
Send ^+s ;open up SaveAs dialog box in Acrobat
Sleep 500 ; wait a bit
Send %indirizzo%\%aovn%.pdf ;write the complete path+filename+.pdf
Send {Enter} ;confirm to save
Send s ;in required confirm to overwrite
Sleep 500 ; wait a bit
Send !{Tab} ;ALT+TAB move to the last window (file-explorer)
return

Return to “Ask For Help”

Who is online

Users browsing this forum: azik0244, Google [Bot], Robbl and 64 guests