Compose a short .ahk script for me.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Deuxdad
Posts: 9
Joined: 08 Feb 2019, 18:14

Compose a short .ahk script for me.

08 Feb 2019, 18:40

Code: Select all

I'm brand new to AutoHotKey and only now am I realizing how powerful this language must be. Because of that, I am asking if it's possible to have someone write a short script for me to use in renaming thousands of .jpg files in Win 10 HOME.

Currently I'm displaying the files using EXTRA LARGE ICONS then selecting the first file. Once selected I press F2 to put me directly into RENAME mode where the filename is then already selected. The script would then SEND a string which wouldn't be changed for 100 files. I would then type the necessary remaining characters for the new filename and press RETURN. At this point I am pressing the right arrow key to select the next file whereupon I would again press F2 to start the process all over again.

If possible I would like to manually select a starting file then press a hotkey combination to start the script. The script would then press the F2 key for me whereupon I would enter the new filename and press RETURN. Pressing RETURN the script would then automatically take me to the next file and press F2 for me.

Any help in this will be greatly appreciated.
Last edited by Deuxdad on 08 Feb 2019, 22:18, edited 1 time in total.
Deuxdad
Posts: 9
Joined: 08 Feb 2019, 18:14

Re: Compose a short .ahk script for me.

08 Feb 2019, 22:17

Forgive my ramblings around this site but this is my first time here.

Here's what I have so far:
#n::
Loop
{
Send, {F2}
Send, ACC 16-9.1
KeyWait, RETURN,D
SEND, {RIGHT}
}
return

This works exactly as I wanted it to except I don't know how to exit the loop without pausing it from the AHK menu.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Compose a short .ahk script for me.

09 Feb 2019, 03:58

Deuxdad wrote:
08 Feb 2019, 22:17
Forgive my ramblings around this site but this is my first time here.

Here's what I have so far:
#n::
Loop
{
Send, {F2}
Send, ACC 16-9.1
KeyWait, RETURN,D
SEND, {RIGHT}
}
return

This works exactly as I wanted it to except I don't know how to exit the loop without pausing it from the AHK menu.
To exit a loop, use break
Refer to https://www.autohotkey.com/docs/commands/Break.htm

When using break to exit a loop, this is usually because some condition was met. Often people use an If statement along with the break.

Pseudo Code

Code: Select all

Loop
{
	Do stuff
	Do stuff

	If (condition met)
	{
	Do this and then
	break
	}
}
return
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Compose a short .ahk script for me.

09 Feb 2019, 05:02

You can also rename files in script itself and rename them with your specific rules, the easiest way being to enumerate files using a_index in a loop.

renaming:
https://autohotkey.com/docs/commands/FileMove.htm
Deuxdad
Posts: 9
Joined: 08 Feb 2019, 18:14

Re: Compose a short .ahk script for me.

09 Feb 2019, 15:59

mast4rwang wrote:
09 Feb 2019, 05:02
You can also rename files in script itself and rename them with your specific rules, the easiest way being to enumerate files using a_index in a loop.

renaming:
https://autohotkey.com/docs/commands/FileMove.htm
Thanks but in this case renaming involves some user generated alpha-numeric text as part of the new name. Each is different.
Deuxdad
Posts: 9
Joined: 08 Feb 2019, 18:14

Re: Compose a short .ahk script for me.

09 Feb 2019, 16:15

Well, after hours of poring through the documentation I finally hit on this. Embarrassingly rude, crude and unattractive, but it works.

#n::
Loop
{
Send, {F2} ;Issue RENAME command
Send, ACC 16-9.2 ;Send text "ACC 16-9.1"
KeyWait, RETURN,D ;Waits for the return key to be pushed down
GetKeyState, State, Shift ;Get the state of a shift key. (U)p or (D)own?
If State = D
Break ;Exit the loop if a shift key is down
Else
Send, {RIGHT} ; Keep going, issue right arrow
}
Return

My utmost appreciation to all those who offered suggestions. One last question however, how do you compose in this forum so that comments at the ends of commands are spaced out from the command for readability?
gregster
Posts: 9114
Joined: 30 Sep 2013, 06:48

Re: Compose a short .ahk script for me.

09 Feb 2019, 17:10

One last question however how do you compose in this forum so that comments at the ends of commands are spaced out from the command for readability?
First, use [code][/code] tags around your code, type them yourself or see Full Editor & Preview editor mode for a button that will insert the tags for you: Look for </> button.
Between the code tags, tab(ulator)s do work.

Code: Select all

Msgbox 				; comment
Deuxdad
Posts: 9
Joined: 08 Feb 2019, 18:14

Re: Compose a short .ahk script for me.

14 Feb 2019, 12:20

Code: Select all

#n::
Loop
{
   Send, {F2}						;Issue RENAME command
   Send, ACC 16-9.6					;Send text "ACC 16-9.1"
   KeyWait, RETURN,D				;Waits for the return key to be pushed down
      GetKeyState, State, Shift		;Get the state of a shift key. (U)p or (D)own?
   If State = D                    
      Break							;Exit the loop if a shift key is down
   Else    
      Send, {RIGHT}					; Keep going, issue right arrow
}
return
Well that seems to work. Thank you very much.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: macromint, peter_ahk, Rauvagol and 317 guests