Please Explain AutoHotkey Scripts Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Dr B

Please Explain AutoHotkey Scripts

19 May 2017, 16:13

[code=autohotkey file=Untitled.ahk][/code]

Greetings:

I plan to use AutoHotkey to format text files in Notepad ++. The formatted text then will be ready for use in another program.

A YouTube video introduced me to the scripts, and I transcribed the scripts into a Notepad++ document. But I don't know how to interpret the scripts, how to use the scripts, or whether I've transcribed them correctly given that the scripts appeared on a low-resolution YouTube video.

Would it be possible for me to post a script, or perhaps all the scripts, to get some help understanding them and using them?

Best,
Dr. B
Doc_B
Posts: 6
Joined: 19 May 2017, 16:00

Re: Please Explain AutoHotkey Scripts

19 May 2017, 17:18

Okay, I'll give an example:

$Numpad0::
Clipboard =
Send ^c
Clipwait
StringReplace, Clipboard, Clipboard, , %A_SPACE%, All
Send ^v
Return


Is the script correct, and does the dollar sign have to be used to activate it?
SirRFI
Posts: 117
Joined: 25 Nov 2015, 16:52

Re: Please Explain AutoHotkey Scripts

19 May 2017, 18:19

There's no limited amount of scripts to post them all and explain them. AutoHotkey is scripting language, so You can create exactly what You need on your own.

Perhaps You should visit the [url="https://autohotkey.com/docs/AutoHotkey.htm"]documentation[/url]? It contains commands/functions along with examples how to use them, tutorial and more.

Example:

Code: [Select all] [Download] GeSHi © Codebox Plus

MyText := "I like bananas and other fruits."
MsgBox % StrReplace(MyText, "bananas", "coconuts")

A string is assigned to variable named "MyText". In next line command MsgBox displays the output/result of StrReplace function, which is ordered to replace word "bananas" to "coconuts" in the variable "MyText".
Doc_B
Posts: 6
Joined: 19 May 2017, 16:00

Re: Please Explain AutoHotkey Scripts

19 May 2017, 19:43

Thanks for the reply. The specific scripts that I borrowed do exactly what I need them to do--provided that I transcribed them correctly and know how to activate them. I've read the tutorial twice, but I was hoping to avoid learning a new language to activate ten scripts! I suppose I'll treat the scripts as puzzles to solve when I have some extra time. I also may post the scripts on the specific niche website to which they pertain, to see if someone can help. Again, thanks for taking the time to reply.
guest3456
Posts: 1983
Joined: 09 Oct 2013, 10:31

Re: Please Explain AutoHotkey Scripts

19 May 2017, 19:47

Doc_B wrote:Okay, I'll give an example:

$Numpad0::
Clipboard =
Send ^c
Clipwait
StringReplace, Clipboard, Clipboard, , %A_SPACE%, All
Send ^v
Return


Is the script correct, and does the dollar sign have to be used to activate it?


looks correct, dollar sign isn't required. just press '0' on the numberpad to the right of the keyboard to activate it

User avatar
jeeswg
Posts: 1517
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Please Explain AutoHotkey Scripts

19 May 2017, 20:11

The $ is only really needed if you do: Send {Numpad0} later in the script. It's to stop a hotkey subroutine triggering itself in an infinite loop. That's the main reason.

This link explains about $:
Hotkeys (Mouse, Joystick and Keyboard Shortcuts)
https://autohotkey.com/docs/Hotkeys.htm

Btw:
Numpad0:: ;works when NumLock is on
NumpadIns:: ;works when NumLock is off

Your script basically looks correct. However this line doesn't really make sense. It would replace nothing with a space:
StringReplace, Clipboard, Clipboard, , %A_SPACE%, All ;doesn't make sense (replace nothing with space)
StringReplace, Clipboard, Clipboard, %A_SPACE%, , All ;makes sense (replace space with nothing)

In fact I tried to run it and I got this error:
Error: "StringReplace" requires that parameter #3 be non-blank.

Cheers.
Doc_B
Posts: 6
Joined: 19 May 2017, 16:00

Re: Please Explain AutoHotkey Scripts

19 May 2017, 21:46

guest3456 wrote:
Doc_B wrote:Okay, I'll give an example:

$Numpad0::
Clipboard =
Send ^c
Clipwait
StringReplace, Clipboard, Clipboard, , %A_SPACE%, All
Send ^v
Return


Is the script correct, and does the dollar sign have to be used to activate it?


looks correct, dollar sign isn't required. just press '0' on the numberpad to the right of the keyboard to activate it



Thanks. I got three of the scripts to work, and I pressed only the designated numberpad keys. That dollar sign indeed seems superfluous, though it's presence doesn't appear to affect at least three of the scripts.
Doc_B
Posts: 6
Joined: 19 May 2017, 16:00

Re: Please Explain AutoHotkey Scripts  Topic is solved

19 May 2017, 22:01

jeeswg wrote:The $ is only really needed if you do: Send {Numpad0} later in the script. It's to stop a hotkey subroutine triggering itself in an infinite loop. That's the main reason.

This link explains about $:
Hotkeys (Mouse, Joystick and Keyboard Shortcuts)
https://autohotkey.com/docs/Hotkeys.htm


Thanks. I'd read the explanation of the $ but wondered if its presence were resulting in the script not working. I think the blank parameter is the culprit.

jeeswg wrote:Btw:
Numpad0:: ;works when NumLock is on
NumpadIns:: ;works when NumLock is off


Yes, I read that and eliminated it as a possible cause.



jeeswg wrote:Your script basically looks correct. However this line doesn't really make sense. It would replace nothing with a space:
StringReplace, Clipboard, Clipboard, , %A_SPACE%, All ;doesn't make sense (replace nothing with space)
StringReplace, Clipboard, Clipboard, %A_SPACE%, , All ;makes sense (replace space with nothing)

In fact I tried to run it and I got this error:
Error: "StringReplace" requires that parameter #3 be non-blank.
Cheers.


I agree with your assessment about the missing parameter. Unfortunately, I wasn't getting error messages when running the file. After deleting the file and writing a new one, I started to get the line-specific error messages. Those messages helped me to identify the blank parameters in several scripts.

For some reason, the 'r and 'n statements did not appear in the third parameter in my file. I don't know why since I transcribed the file last evening letter by letter. But here's how the script should read:

$Numpad0::
clipboard =
Send ^c
ClipWait
StringReplace, clipboard, clipboard, 'r'n, %A_Space%, All
Send ^v
Return

Still, I can't get the script to work. I think I don't have the correct symbol preceding the r or n. I'm using a single quotation mark, but I don't think that's correct. I haven't been able to find an apostrophe or whatever it is in the documentation.

Support for my hypothesis that it's that parameter comes from my ability to run scripts without that parameter. For example, the following two scripts run fine.

$Numpad5::
Clipboard =
Send ^c
ClipWait
Clipboard := "<b>" clipboard"</b>"
Send ^v
Return

$Numpad6::
Clipboard =
Send ^c
ClipWait
Clipboard := "<i>" clipboard"</i>"
Send ^v
Return

These two scripts mark up the selected text with notation to make it bold or italic. The scripts work fine, and the text becomes bold or italic. Note that the scripts do not have a StringReplace line and the potentially problematic 'r 'n.

What is the character the precedes each of those letters?
User avatar
jeeswg
Posts: 1517
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Please Explain AutoHotkey Scripts

19 May 2017, 22:07

96 0060 ` GRAVE ACCENT [backtick]
39 0027 ' APOSTROPHE

Backtick is to the left of the 1 key on my keyboard. [EDIT: to the *left*.]

I would use:
Last edited by jeeswg on 21 May 2017, 18:44, edited 1 time in total.
Doc_B
Posts: 6
Joined: 19 May 2017, 16:00

Re: Please Explain AutoHotkey Scripts

19 May 2017, 22:37

jeeswg wrote:96 0060 ` GRAVE ACCENT [backtick]
39 0027 ' APOSTROPHE

Backtick is to the right of the 1 key on my keyboard.

I would use:


Thanks. I replaced the single quotation mark with the grave accent in the specified parameter. Both iterations of the script work in Notepad, but neither works in Notedpad++. Not sure why.
SirRFI
Posts: 117
Joined: 25 Nov 2015, 16:52

Re: Please Explain AutoHotkey Scripts

20 May 2017, 05:43

Doc_B wrote:
jeeswg wrote:96 0060 ` GRAVE ACCENT [backtick]
39 0027 ' APOSTROPHE

Backtick is to the right of the 1 key on my keyboard.

I would use:


Thanks. I replaced the single quotation mark with the grave accent in the specified parameter. Both iterations of the script work in Notepad, but neither works in Notedpad++. Not sure why.

I didn't follow the discussion, but if it's about new line character - perhaps in Notepad++ You have Unix EndOfLine, which is just \n, not \r\n like in Windows format. To ensure it script works regardless of the EOL, You can use:
Doc_B
Posts: 6
Joined: 19 May 2017, 16:00

Re: Please Explain AutoHotkey Scripts

21 May 2017, 15:05

SirRFI wrote:
Doc_B wrote:
jeeswg wrote:96 0060 ` GRAVE ACCENT [backtick]
39 0027 ' APOSTROPHE

Backtick is to the right of the 1 key on my keyboard.

I would use:


Thanks. I replaced the single quotation mark with the grave accent in the specified parameter. Both iterations of the script work in Notepad, but neither works in Notedpad++. Not sure why.

I didn't follow the discussion, but if it's about new line character - perhaps in Notepad++ You have Unix EndOfLine, which is just \n, not \r\n like in Windows format. To ensure it script works regardless of the EOL, You can use:


Thanks for the code. I discovered the problem: the script seeks to replace both a carriage return and a line break with a space. However, the text that I experimented on in Notepad++ had only line breaks. After finding and replacing all line breaks with carriage returns and line breaks, the script worked. Indeed, all the scripts I tested now work, a functionality that dramatically simplifies my marking up text for editing and formatting.

This lesson has saved me a lot of time. My thanks to both contributors to this thread!

Return to “Ask For Help”

Who is online

Users browsing this forum: autopuff, divanebaba, MaxAstro, tank, Xtra, Yahoo [Bot] and 35 guests