Script that ask for the loop count then perform the loop Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
soheill0098
Posts: 69
Joined: 01 Sep 2020, 12:28

Script that ask for the loop count then perform the loop

Post by soheill0098 » 09 Aug 2021, 17:45

I have this script that save the content of each open tab of Microsoft Edge browser in pdf,

Code: Select all

#SingleInstance,force
^!e::
loop,8
{
^!a::
sleep,300
send,^p
sleep,5000
click,155,746
sleep,5000
send,{Enter}
sleep,1000
send,^w
sleep,2000
}
Esc:: ExitApp
return
But I set loop count 8 for the script but sometimes there are less or more opened tabs that I want to save. So every time I should open the script and change the number 8 to the number I want and reload the script.

I wonder is it possible to add some lines of script to it so that every time I run the script it ask me for number of iterations (loop count) that I want the program perform the loop? (for example by showing a box and I type the loop number in the box.)


Jakson
Posts: 47
Joined: 25 Jun 2021, 15:19

Re: Script that ask for the loop count then perform the loop

Post by Jakson » 09 Aug 2021, 17:59

soheill0098 wrote:
09 Aug 2021, 17:45
But I set loop count 8 for the script but sometimes there are less or more opened tabs that I want to save. So every time I should open the script and change the number 8 to the number I want and reload the script.

I wonder is it possible to add some lines of script to it so that every time I run the script it ask me for number of iterations (loop count) that I want the program perform the loop? (for example by showing a box and I type the loop number in the box.)
I'm not sure why its not running all 8 times. In my experience, loops will execute until something melts or the loop finishes execution.

Try an input box. I had a very similar issue except I had to use an .ini file to pass the loop number variable between scripts.

Code: Select all


Inputbox, [Your Var here], give me the number of times to loop.

[In the following section of code]

#SingleInstance,force
^!e::
loop,%[Your Var Here]%
^!a::
sleep,300
send,^p
sleep,5000
click,155,746
sleep,5000
send,{Enter}
sleep,1000
send,^w
sleep,2000
}
Esc:: ExitApp
return

-Untested-

Input box sounds like your way forward. https://www.autohotkey.com/docs/commands/InputBox.htm - AHK help document.

You can pull out the variable you write into the inputbox by enclosing the variable name you used previously in percent signs %%

Code: Select all

 %YourVar'sContents%
Remember that when you declare the variable in the inputbox command line you have to use the same variable name in your Loop counter, IE

Code: Select all

Inputbox, MyVariable, Give me the # of Loops!

Loop,%MyVariable%

; looping...


If you don't want to be prompted to write a new value in each time I'd think the solution would be to simply write the integer, as the number of loops, in the loop command line...

Code: Select all

Loop, 10
;code...
For example.

Good luck!

soheill0098
Posts: 69
Joined: 01 Sep 2020, 12:28

Re: Script that ask for the loop count then perform the loop

Post by soheill0098 » 09 Aug 2021, 18:04

Jakson wrote:
09 Aug 2021, 17:59
soheill0098 wrote:
09 Aug 2021, 17:45
But I set loop count 8 for the script but sometimes there are less or more opened tabs that I want to save. So every time I should open the script and change the number 8 to the number I want and reload the script.

I wonder is it possible to add some lines of script to it so that every time I run the script it ask me for number of iterations (loop count) that I want the program perform the loop? (for example by showing a box and I type the loop number in the box.)
I'm not sure why its not running all 8 times. In my experience, loops will execute until something melts or the loop finishes execution.

Try an input box. I had a very similar issue except I had to use an .ini file to pass the loop number variable between scripts.

Code: Select all


Inputbox, [Your Var here], give me the number of times to loop.

[In the following section of code]

#SingleInstance,force
^!e::
loop,%[Your Var Here]%
^!a::
sleep,300
send,^p
sleep,5000
click,155,746
sleep,5000
send,{Enter}
sleep,1000
send,^w
sleep,2000
}
Esc:: ExitApp
return

-Untested-

Input box sounds like your way forward. https://www.autohotkey.com/docs/commands/InputBox.htm - AHK help document.

You can pull out the variable you write into the inputbox by enclosing the variable name you used previously in percent signs %%

Code: Select all

 %YourVar'sContents%
Remember that when you declare the variable in the inputbox command line you have to use the same variable name in your Loop counter, IE

Code: Select all

Inputbox, MyVariable, Give me the # of Loops!

Loop,%MyVariable%

; looping...


If you don't want to be prompted to write a new value in each time I'd think the solution would be to simply write the integer, as the number of loops, in the loop command line...

Code: Select all

Loop, 10
;code...
For example.

Good luck!

Thanks! Sorry my English is not very well maybe I couldn't represent what I meant. I meant by the script I wrote it always save 8 tabs and for example if there are 10 tabs open I have to edit the script and change the number of the loop.

soheill0098
Posts: 69
Joined: 01 Sep 2020, 12:28

Re: Script that ask for the loop count then perform the loop

Post by soheill0098 » 09 Aug 2021, 18:18

mikeyww wrote:
09 Aug 2021, 17:49
InputBox is a good choice for that.
Thank you very much for the help! I found a script here https://autohotkey.com/board/topic/39431-solved-input-box-to-enter-loop-quantity/with the InputBox that do what I want. :D

User avatar
emrekarahan0001
Posts: 25
Joined: 18 Jan 2021, 14:19

Re: Script that ask for the loop count then perform the loop

Post by emrekarahan0001 » 11 Aug 2021, 05:47

try this ;)

Code: Select all

Gui, +Lastfound +Toolwindow
Gui, Add, Edit, x5 y10 w20 h20 vEdit1,
Gui, Add, Button, x+5 y10 w65 h20 gSave, OK
Gui, Show, w100 h40,
Return

Save:
Guicontrolget, Edit1
Loop, %Edit1%
{
Sleep,300
Send,^p
Sleep,5000
Click,155,746
Sleep,5000
Send,{enter}
Sleep,1000
Send,^w
Sleep,2000
}
Return

GuiEscape:
GuiClose:
ExitApp

Post Reply

Return to “Ask for Help (v1)”