Criei um script AHK básico que adiciona metadados exclusivos a cada arquivo em um sistema que uso todos os dias. A ideia é adicionar _01 ao primeiro arquivo seguido de _02 ao segundo arquivo e subir indefinidamente até eu sair do script.
No começo, senti que estava fazendo isso por um longo caminho e não tinha certeza do que era necessário para tornar o script menor e menos doloroso de editar.
Aqui está o roteiro:
#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.
F3::
{
Send, {LAlt}
Sleep, 20
Send, {Right}
Sleep, 200
Send, {Right}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 107, 30
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 346, 38
Sleep, 200
Send, ^v
Sleep, 100
Send, _01
Sleep, 200
Send, {Enter}
Sleep, 200
Send, {Enter}
Sleep, 200
MouseClick, Left, 91, 102
Sleep, 100
MouseClick, Left, 92, 100
Sleep, 100
MouseClick, Left, 147, 156
Sleep, 100
Send, {Down}
Send, {LAlt}
Sleep, 20
Send, {Right}
Sleep, 200
Send, {Right}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 107, 30
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 346, 38
Sleep, 200
Send, ^v
Sleep, 100
Send, _02
Sleep, 200
Send, {Enter}
Sleep, 200
Send, {Enter}
Sleep, 200
MouseClick, Left, 91, 102
Sleep, 100
MouseClick, Left, 92, 100
Sleep, 100
MouseClick, Left, 147, 156
Sleep, 100
Send, {Down}
Send, {LAlt}
Sleep, 20
Send, {Right}
Sleep, 200
Send, {Right}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 107, 30
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 346, 38
Sleep, 200
Send, ^v
Sleep, 100
Send, _03
Sleep, 200
Send, {Enter}
Sleep, 200
Send, {Enter}
Sleep, 200
MouseClick, Left, 91, 102
Sleep, 100
MouseClick, Left, 92, 100
Sleep, 100
MouseClick, Left, 147, 156
Sleep, 100
Send, {Down}
Send, {LAlt}
Sleep, 20
Send, {Right}
Sleep, 200
Send, {Right}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 107, 30
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 346, 38
Sleep, 200
Send, ^v
Sleep, 100
Send, _04
Sleep, 200
Send, {Enter}
Sleep, 200
Send, {Enter}
Sleep, 200
MouseClick, Left, 91, 102
Sleep, 100
MouseClick, Left, 92, 100
Sleep, 100
MouseClick, Left, 147, 156
Sleep, 100
Send, {Down}
Send, {LAlt}
Sleep, 20
Send, {Right}
Sleep, 200
Send, {Right}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 107, 30
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 346, 38
Sleep, 200
Send, ^v
Sleep, 100
Send, _05
Sleep, 200
Send, {Enter}
Sleep, 200
Send, {Enter}
Sleep, 200
MouseClick, Left, 91, 102
Sleep, 100
MouseClick, Left, 92, 100
Sleep, 100
MouseClick, Left, 147, 156
Sleep, 100
Send, {Down}
}
Como você pode ver, tive que copiar/colar todo o script e alterar o _01 para _02 na próxima parte, seguido por _03, _04 e _05.
Eu descobri como fazer isso com o uso de Loop + A_index e funciona bem como o exemplo acima:
#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.
F3::
Loop, 5
{
Send, {LAlt}
Sleep, 20
Send, {Right}
Sleep, 200
Send, {Right}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 107, 30
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 346, 38
Sleep, 200
Send, ^v
Sleep, 100
Send, _
Sleep, 100
Send %A_Index%
Sleep, 200
Send, {Enter}
Sleep, 200
Send, {Enter}
Sleep, 200
MouseClick, Left, 91, 102
Sleep, 100
MouseClick, Left, 92, 100
Sleep, 100
MouseClick, Left, 147, 156
Sleep, 100
Send, {Down}
}
I now need to be able to set the starting value of %A_index% with the use of a input box at the beginning of the script.
I want to be able to enter any number into the inputbox and have %A_index% work sequentially starting from that number.
So since A_Index simply keeps track of the current loop iteration, and therefore is a built-in internal value that cannot be changed...
...what i'm essentially asking is:
How do I get the script to start from a specific loop iteration using inputbox?
Does anyone know how this can be achieved?
You need to use another intermediate variable, convert
A_Index
to a 0-indexed loop count by subtracting 1, and add them together inside the loop