AutoHotkey: display the various AutoHotkey/Hotstring reported in a file

Luis Diaz
Luis Diaz used Ask the Experts™
on
Hello experts,

I have more than 90 AutoHotkey/Hotstring scripts reported in my AutoHotkey/Hotstring file that I use on a daily basis.
Sometimes I forgot the ones's that I don't use frequently. I was wondering how do you manage this and if there is an approach to display the various AutoHotkey/Hotstring reported in the file. The idea will be to relate to another AutoHotkey so when I call it, it reads and displays in the clipboard or a combobox the various AutoHotkey/Hotstring reported in the file so I can swiftly access to the one that I forgot and call it. My various AutoHotkey/Hotstring have a comment above of each of them with the following structure:
Example:

;====================================
;Run Excel 
;====================================

#!e::
If (FileExist(Excel32))
  Run,%Excel32%
Else
If (FileExist(Excel64))
  Run,%Excel64%
Else
  MsgBox,4112,Error,Neither 32-bit nor 64-bit Excel exists on this system
Return

Open in new window


Therefore I was thinking to read the AutoHotkey/Hotstring file and select just the comment and the next line which contains "::" which is the AutoHotkey/Hotstring. Then if I have it in a clipboard I can paste it notepad++ and launch the search of the AutoHotkey/Hotstring that I am looking for.
Let me know what do you think or if you have another proposal.

Thank you for your help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Hi Luis,
My AutoHotkey script that loads at Window startup has 172 hotkeys/hotstrings, so I experience the same issue as you. I wrote a script that helps me with the problem and I'm happy to share it with you, but I'm working on a business client's issue right now. I should be able to get to this in the few hours. In the meantime, you may find this EE thread to be an interesting read:

https://www.experts-exchange.com/questions/29154231/Create-hyperlinks-more-quickly-move-to-certain-lines-in-Notepad.html

Regards, Joe
Luis DiazIT consultant

Author

Commented:
Hi Joe,
Thank you very much for your comment.
I will take a look on your link and let you know. in the meantime and I will keep the question opened and I am looking forward for your script that help you with your problem.
Have a great Sunday and a great week!
Regards,
Luis.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
> My various AutoHotkey/Hotstring have a comment below of each of them with the following structure

A few questions about that:

(1) The example indicates that you mean "above", not "below"...right?

(2) Is there always a blank line above the hotkey/hotstring definition (such as line 4 in your example)?

(3) Is there always a ";====================================" line above the blank line (such as line 3 in your example)?

(4) Are you willing to change your commenting method to putting the comment on the same line as the hotkey/hotstring? For example, something like this:

#!e:: ; === Run Excel ===

I'm not done with my client's issue yet, but wanted to get you working on these questions in the meantime. Regards, Joe
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018
Commented:
Hi Luis,
If you read the thread about FiSH, you know that my method of defining hotkeys/hotstrings is to put on the first line either the command itself, such as :*:ppx::PaperPort, or a comment, such as !^-:: ;bullet (149/x95) — that's the reason for question #4 in my previous post. With that approach, the simple AutoHotkey script below (which I named ShowHot.ahk) creates my list of hotkeys/hotstrings and opens the list in the text editor that owns the TXT file extension on my system:

#Warn,UseUnsetLocal ; warning on uninitialized variables
#NoEnv ; avoid checking empty variables to see if they are environment variables
#SingleInstance Force ; replace old instance immediately
SetBatchLines,-1 ; run at maximum speed

HotScript:="C:\AHK\hotkeys-hotstrings-startup.ahk"
TempFile:=A_Temp . "\~hotkeys-hotstrings.txt"

HotID:="::"
HotList:=""
Loop,Read,%HotScript%
{
  If (InStr(A_LoopReadLine,HotID)) ; skip if this line is not a hotkey/hotstring definition
  {
    If (SubStr(A_LoopReadLine,RegExMatch(A_LoopReadLine,"\S"),1)=";") ; skip if it is commented out
      Continue
    HotList:=HotList . A_LoopReadLine . "`n" ; concatenate this hotkey/hotstring to list
  }
}
Sort,HotList
FileDelete,%TempFile%
FileAppend,%HotList%,%TempFile%
Run,%TempFile%
ExitApp

Open in new window

I run this script from my startup hotkeys/hotstrings script via a hotkey, as follows:

!^F1::Run,C:\AHK\ShowHot.ahk
Return

Open in new window

As you can see, I use Alt+Ctrl+F1 for it, but, of course, you can make it any hotkey you want...just don't forget it. :)

I went with Loop,Read instead of FileRead for simplicity in coding and because the file is relatively small, so performance is not an issue.

The script handles comment lines with a semi-colon but not comment blocks (beginning with /* and ending with */). It would not be difficult to handle comment blocks (FiSH does), but it's not an issue for me, so I never put it into this script.

If you're not willing to put either the command itself or the comment on the first line of each hotkey/hotstring, then, of course, the script needs revision. It would have to keep a buffer of previous lines, such as lines 1-4 in the example you posted, and then when it finds a hotkey/hotstring, such as line 5 in the example you posted, it would have to go back to the buffered lines and get the comment...more difficult, but very doable. Regards, Joe
Luis DiazIT consultant

Author

Commented:
Thank you Joe for your comment.
>(1) The example indicates that you mean "above", not "below"...right?
Yes, I have just reviewed the question.

Concerning the read method, I prefer to keep comment structure with the name of each AutoHotkey/Hotstring like this:
;====================================
;Command
;====================================

Open in new window


This help me to have a cleaned AutoHotkey/Hotstring file, and be able to swiftly review it.

I am in with the buffer lines approach.
I propose the following approach:
Find the string which contains: "::" and read the 4th line above it (just the 4th line in order to get just the comment (;Command) in my example
without (";============================")


Thank you for your help.
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
How about some PowerShell that shows a form that you can search immediately:
Get-Content 'C:\Temp\Whatever.ahk' |
	Select-String -Pattern '^(?!;).*?::' -Context 3,0 |
	Select-Object @{n='HotKey'; e={$_.Line}}, @{n='Command'; e={$_.Context.PreContext[0].Trim('; ')}} |
	Out-GridView -Wait

Open in new window

And a version as a single command:
powershell.exe -Command "Get-Content 'C:\Temp\Whatever.ahk' | Select-String -Pattern '^(?!;).*?::' -Context 3,0 | Select-Object @{n='HotKey'; e={$_.Line}}, @{n='Command'; e={$_.Context.PreContext[0].Trim('; ')}} | Out-GridView -Wait"

Open in new window

Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018
Commented:
OK, here's a modified version of my AutoHotkey script above that does it:

#Warn,UseUnsetLocal ; warning on uninitialized variables
#NoEnv ; avoid checking empty variables to see if they are environment variables
#SingleInstance Force ; replace old instance immediately
SetBatchLines,-1 ; run at maximum speed

HotScript:="C:\AHK\hotkeys-hotstrings-startup.ahk"
TempFile:=A_Temp . "\~hotkeys-hotstrings.txt"

HotID:="::"
HotList:=Line2:=Line3:=Line4:=Line5:=""
Loop,Read,%HotScript%
{
  Line1:=Line2
  Line2:=Line3
  Line3:=Line4
  Line4:=Line5
  Line5:=A_LoopReadLine
  If (InStr(A_LoopReadLine,HotID)) ; skip if this line is not a hotkey/hotstring definition
  {
    If (SubStr(A_LoopReadLine,RegExMatch(A_LoopReadLine,"\S"),1)=";") ; skip if it is commented out
      Continue
    HotList:=HotList . Line5 . " ==> " . Line2 . "`n" ; concatenate this hotkey/hotstring to list
  }
}
Sort,HotList
FileDelete,%TempFile%
FileAppend,%HotList%,%TempFile%
Run,%TempFile%
ExitApp

Open in new window

I tested it on this input file:

;====================================
;Run Excel
;====================================

#!e::
If (FileExist(Excel32))
  Run,%Excel32%
Else
If (FileExist(Excel64))
  Run,%Excel64%
Else
  MsgBox,4112,Error,Neither 32-bit nor 64-bit Excel exists on this system
Return

;====================================
;Run PowerPoint
;====================================

#!p::
If (FileExist(PowPnt32))
  Run,%PowPnt32%
Else
If (FileExist(PowPnt64))
  Run,%PowPnt64%
Else
  MsgBox,4112,Error,Neither 32-bit nor 64-bit PowerPoint exists on this system
Return

;====================================
;Run Word
;====================================

#!w::
If (FileExist(Word32))
  Run,%Word32%
Else
If (FileExist(Word64))
  Run,%Word64%
Else
  MsgBox,4112,Error,Neither 32-bit nor 64-bit Word exists on this system
Return

Open in new window

The result is this:

#!e:: ==> ;Run Excel
#!p:: ==> ;Run PowerPoint
#!w:: ==> ;Run Word

Open in new window

Regards, Joe
Luis DiazIT consultant

Author

Commented:
Thank you very much Joe, unable to test it right inow. I will test it today.
Luis DiazIT consultant

Author

Commented:
ObdA, thank you for your Powershell approach. I will also test it and keep you informed.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
OK, it's 1:00am here...I'll check back into the thread first thing in my morning tomorrow to see how you're doing. Regards, Joe
Luis DiazIT consultant

Author

Commented:
Joe,

I tested your proposal and it works for me.
Just some questions and adjustments that I would like to review with you:
1>Structure of lines reported in txt file.
Example for the following AutoHotkey:
;====================================
;Run SciTE
;====================================

#!i::
If (FileExist(SciTE1))
  Run,%SciTE1%
Else
If (FileExist(SciTE2))
  Run,%SciTE2%
Else
  MsgBox,4112,Error,Neither SciTE exists on your system system.
Return

Open in new window


Txt file displays
 
#!i:: ==> ;Run SciTE

Open in new window


I was wondering if there is a way to get ride of the semicolon #!i:: ==> ;Run SciTE in order to have the following in txt file:
#!i:: ==> Run SciTE

Open in new window


2>When the command is at the same line as the AutoHotkey/Hotstring it is also displayed in the txt file:
Example:
;====================================
;Run Programs & Features
;====================================

#^a::Run, C:\Windows\System32\appwiz.cpl
Return

Open in new window

Txt file displays:
#^a::Run C:\Windows\System32\appwiz.cpl ==> ;Run Programs & Features

Open in new window


The workaround will be to have the Run bellow the AutoHotkey, however I would like to have your opinion on this prior of modifying AutoHotkey/Hotstring file.
Please note that I have a lot of AutoHotkey/Hotstring in which commands are placed at the same line as the AutoHotkey/Hotstring.

3>The following AutoHotkey
;====================================
;Edit file based on extension
;====================================

#NoEnv ; avoid checking empty variables to see if they are environment variables. Potential regressions if so comment this line
#SingleInstance Force ; replace old instance immediately
SetBatchLines,-1 ; run at maximum speed

+F4::
FileSelected:=GetSelectedFile()
SplitPath,FileSelected,,,FileExt
If (FileExt="ahk")
  Run,"%SciTE4exe%" "%FileSelected%"
Else
If (FileExt="vbs")
  Run,"%Vbseditexe%" "%FileSelected%"
Else
If (FileExt="ps1")
  Run,"%Powershellexe%" "%FileSelected%"
Else
  Run,"%NPPexe%" "%FileSelected%"
Return

Open in new window


Displays the following:
+F4:: ==> #SingleInstance Force ; replace old instance immediately

Open in new window


It doesn't meet the buffer requirement. I was wondering if I adjust as following to meet the buffer requirement:
;====================================
;Edit file based on extension
;====================================

+F4::
#NoEnv ; avoid checking empty variables to see if they are environment variables. Potential regressions if so comment this line
#SingleInstance Force ; replace old instance immediately
SetBatchLines,-1 ; run at maximum speed

FileSelected:=GetSelectedFile()
SplitPath,FileSelected,,,FileExt
If (FileExt="ahk")
  Run,"%SciTE4exe%" "%FileSelected%"
Else
If (FileExt="vbs")
  Run,"%Vbseditexe%" "%FileSelected%"
Else
If (FileExt="ps1")
  Run,"%Powershellexe%" "%FileSelected%"
Else
  Run,"%NPPexe%" "%FileSelected%"
Return

Open in new window


4> Instead of having two different AutoHotkey/Hotstring files, I was wondering why not include in the reference AutoHotkey/Hotstring the AutoHotkey which allow us to read the various AutoHotkey/Hotstring and display them in txt file.

The idea will be to use %A_ScriptFullPath% for HotScript variable

This will allows me to have in the same file the AutoHotkey/Hotstring and functions instead of managing multiple files for the daily basis actions.
I prefer this approach as I use multiple computers based on my location as a result if I need to update my AutoHotkey/Hotstring file, ensure consistency and proper versioning among the various computers I need to simplify as much as I can. By having just one file I think I can reach simplification.
Let me know if this can be done and also your opinion on this.

Thank you for your help.
Regards,
Luis.
Luis DiazIT consultant

Author

Commented:
I also tested ObdA powershell approach and I think that we should consider this as an excellent approach.
It has the benefit to display a grid view which allows us to swiftly add filters based on the column and effectively perform search in real time as the information reported in filter is automatically show up.
Grid view powershell
Thank you very much for this approach!
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018
Commented:
> I was wondering if there is a way to get rid of the semicolon

Sure, just use a simple StrReplace call to remove it.

> The workaround will be to have the Run bellow the AutoHotkey, however I would like to have your opinion on this prior of modifying AutoHotkey/Hotstring file.

That's a good approach. I added it that way to my test file and it works fine.

> I was wondering if I adjust as following to meet the buffer requirement

Those statements shouldn't be there, anyway. Move these lines to the beginning of your startup hotkeys/hotstrings script...BEFORE any hotkeys or hotstrings are defined:

#NoEnv ; avoid checking empty variables to see if they are environment variables. Potential regressions if so comment this line
#SingleInstance Force ; replace old instance immediately
SetBatchLines,-1 ; run at maximum speed

Open in new window


> Instead of having two different AutoHotkey/Hotstring files, I was wondering why not include in the reference AutoHotkey/Hotstring the AutoHotkey which allow us to read the various AutoHotkey/Hotstring and display them in txt file.

Sure, that's fine. Here's the revised AutoHotkey code (put it in your startup hotkeys/hotstrings script):

;====================================
;Display all hotkeys and hotstrings
;====================================

!^F1::
TempFile:=A_Temp . "\~hotkeys-hotstrings.txt"
HotID:="::"
HotList:=Line2:=Line3:=Line4:=Line5:=""
Loop,Read,%A_ScriptFullPath%
{
  Line1:=Line2
  Line2:=Line3
  Line3:=Line4
  Line4:=Line5
  Line5:=A_LoopReadLine
  If (InStr(Line5,"HotID:=")) ; skip if this is the HotID assignment statement
    Continue
  If (InStr(A_LoopReadLine,HotID)) ; skip if this line is not a hotkey/hotstring definition
  {
    If (SubStr(A_LoopReadLine,RegExMatch(A_LoopReadLine,"\S"),1)=";") ; skip if it is commented out
      Continue
    HotList:=HotList . Line5 . " ==> " . StrReplace(Line2,";","",1) . "`n" ; remove semi-colon and concatenate this hotkey/hotstring to list
  }
}
Sort,HotList
FileDelete,%TempFile%
FileAppend,%HotList%,%TempFile%
Run,%TempFile%
Return

Open in new window

I made the hotkey Alt+Ctrl+F1. As always, make it whatever you want. Regards, Joe
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
> we should consider this

you may consider it however you want...I don't do PowerShell unless absolutely necessary. :)
Luis DiazIT consultant

Author

Commented:
Joe, thank you for your feedback.
I will test las proposal tomorrow morning (GMT+1) and let you know.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Sounds good. I'm in GMT-6.
Luis DiazIT consultant

Author

Commented:
Joe,

I tested last version and it works!

I modified AutoHotkey to Ctrl+Shift+F6 and also A_Temp variable by A_ScriptDir as I prefer to have txt file at the same directory of ahk file.

;====================================
;Display all AutoHotkey/Hotstring in a txt file
;====================================

+^F6::
TempFile:=A_ScriptDir . "\~hotkeys-hotstrings.txt"
HotID:="::"
HotList:=Line2:=Line3:=Line4:=Line5:=""
Loop,Read,%A_ScriptFullPath%
{
  Line1:=Line2
  Line2:=Line3
  Line3:=Line4
  Line4:=Line5
  Line5:=A_LoopReadLine
  If (InStr(Line5,"HotID:=")) ; skip if this is the HotID assignment statement
    Continue
  If (InStr(A_LoopReadLine,HotID)) ; skip if this line is not a hotkey/hotstring definition
  {
    If (SubStr(A_LoopReadLine,RegExMatch(A_LoopReadLine,"\S"),1)=";") ; skip if it is commented out
      Continue
    HotList:=HotList . Line5 . " ==> " . StrReplace(Line2,";","",1) . "`n" ; remove semi-colon and concatenate this hotkey/hotstring to list
  }
}
Sort,HotList
FileDelete,%TempFile%
FileAppend,%HotList%,%TempFile%
Run,%TempFile%
Return

Open in new window


Let me know if you see something wrong above.

Additionally I have 2 last questions:
1) Concerning the ~ character prior the name: hotkeys-hotstrings.txt. What is the purpose of adding this character?
2) How the reading is performed and information is reported in txt file as I don't have the same order as the AutoHotkey/Hotstring reported in my ahk file.
Example :
#!c:: ==> Run Cmd

Open in new window

Is the first AutoHotkey reported in my ahk file however it appears at line 11 in txt files.
Is there a way to have the same order for both ahk and txt file? If so how should I proceed?
Thank you in advance for your feedback.
Developer
Fellow 2017
Most Valuable Expert 2018
Commented:
> I tested last version and it works!

Glad to hear it!

> I modified AutoHotkey to Ctrl+Shift+F6 and also A_Temp variable by A_ScriptDir as I prefer to have txt file at the same directory of ahk file.

OK, your AutoHotkey code looks good.

> Let me know if you see something wrong above.

I reviewed your code...I don't see anything wrong. Also, I tested it here...works perfectly!

> What is the purpose of adding this character?

It is somewhat of a Windows standard that temporary files have that character at the beginning of their file names. It is not required...if you don't like it, remove it...it has no effect on operation...it behaves like any other character in a file name. It is simply an indicator to the user that the program which created the file considers it to be a temporary file.

> How the reading is performed and information is reported in txt file as I don't have the same order as the AutoHotkey/Hotstring reported in my ahk file.

That's because I decided to sort the list before putting it in the output file. My thinking is that sorted order is better than the order in the hotkeys/hotstrings script.

> Is there a way to have the same order for both ahk and txt file? If so how should I proceed?

Simply remove the Sort command (line 25 in the code that you posted).

Regards, Joe
Luis DiazIT consultant

Author

Commented:
Thank you Joe, this question was crucial for my daily actions and proposals will help me a lot!
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
You're welcome, Luis, I'm glad that it will help you every day. Regards, Joe
Luis DiazIT consultant

Author

Commented:
Joe,

I started using the AutoHotkey script and I found that is very useful.
I take the opportunity to task you two questions.

1. I have some AutoHotkey which use:
#IfWinActive,ahk_class CabinetWClass

Open in new window


And therefore have the following structure:
;====================================
;Windows Explorer: copy path
;====================================

#IfWinActive,ahk_class CabinetWClass
+F1::
Send, !hcp
Return
#If

Open in new window

They don't respect the buffer structure.
I was wondering if I can proceed like this:
;====================================
;Windows Explorer: copy path
;====================================

+F1::
#IfWinActive,ahk_class CabinetWClass
Send, !hcp
Return
#If

Open in new window


To make them meet the buffer structure.

2. I was wondering if there is a way to display in txt line number in which is located the AutoHotkey/Hotstring.
Current version report the following in txt file:
+^F6:: ==> Display all AutoHotkey/Hotstring in a txt file

Open in new window

I would like to add line number like this:
+^F6:: ==> Display all AutoHotkey/Hotstring in a txt file (line 455) 

Open in new window

Line 455 is the line in which is located the AutoHotkey/Hotstring.
By reporting this information I can swiftly check where is located the AutoHotkey.

Let me know your feedback on those points.

Thank you for your help.
Luis DiazIT consultant

Author

Commented:
@oBdA: based on the proposal :
https://www.experts-exchange.com/questions/29166455/AutoHotkey-display-the-various-AutoHotkey-Hotstring-reported-in-a-file.html#a42992936

I was wondering if there is a way to add as column in the grid view the line number.

Thank you for your help.
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
Expanded:
Get-Content 'C:\Temp\Whatever.ahk' |
	Select-String -Pattern '^(?!;).*?::' -Context 3,0 |
	Select-Object @{n='HotKey'; e={$_.Line}}, @{n='Command'; e={$_.Context.PreContext[0].Trim('; ')}}, @{n='LineNumber'; e={$_.LineNumber}} |
	Out-GridView -Wait

Open in new window

One-liner:
powershell.exe -Command "Get-Content 'C:\Temp\Whatever.ahk' | Select-String -Pattern '^(?!;).*?::' -Context 3,0 | Select-Object @{n='HotKey'; e={$_.Line}}, @{n='Command'; e={$_.Context.PreContext[0].Trim('; ')}}, @{n='LineNumber'; e={$_.LineNumber}} | Out-GridView -Wait"

Open in new window

Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
> I started using the AutoHotkey script and I found that is very useful.

I'm very glad to hear it!

> #IfWinActive,ahk_class CabinetWClass

That creates context-sensitive hotkeys (if you want to look back, we've discussed this at length in previous threads). You may learn about it here:
https://www.autohotkey.com/docs/commands/_IfWinActive.htm

There are many #If directives, beginning in the doc here:
https://www.autohotkey.com/docs/commands/_If.htm

You may recall from our past threads that the #IfWin directives are positional, meaning they affect all hotkeys and hotstrings physically beneath them in the script. That's why you should turn off the context sensitivity as appropriate, which is done via the #IfWin directive with all parameters omitted (also, they are mutually exclusive, so only the most recent one will be in effect).

I hope that helps you to understand what's going on with your #IfWinActive,ahk_class CabinetWClass directive. In any case, I don't know what you mean when you say, "They don't respect the buffer structure." Please explain further what you are asking.

> I was wondering if I can proceed like this

After reading the above, I hope you'll understand that you likely don't want to move #IfWinActive,ahk_class CabinetWClass beneath the +F1:: line.

> To make them meet the buffer structure.

Once again, I don't know what you mean by that.

> I was wondering if there is a way to display in txt line number in which is located the AutoHotkey/Hotstring.

Yes, very easy.

> +^F6:: ==> Display all AutoHotkey/Hotstring in a txt file (line 455)

Revised AutoHotkey code below does it:

;====================================
;Display all AutoHotkey/Hotstring in a txt file
;====================================

+^F6::
TempFile:=A_ScriptDir . "\~hotkeys-hotstrings.txt"
HotID:="::"
HotList:=Line2:=Line3:=Line4:=Line5:=""
LineNum:=0
Loop,Read,%A_ScriptFullPath%
{
  LineNum:=LineNum+1
  Line1:=Line2
  Line2:=Line3
  Line3:=Line4
  Line4:=Line5
  Line5:=A_LoopReadLine
  If (InStr(Line5,"HotID:=")) ; skip if this is the HotID assignment statement
    Continue
  If (InStr(A_LoopReadLine,HotID)) ; skip if this line is not a hotkey/hotstring definition
  {
    If (SubStr(A_LoopReadLine,RegExMatch(A_LoopReadLine,"\S"),1)=";") ; skip if it is commented out
      Continue
    HotList:=HotList . Line5 . " ==> " . StrReplace(Line2,";","",1) . " (line " . LineNum . ")`n" ; remove semi-colon and concatenate this hotkey/hotstring to list
  }
}
FileDelete,%TempFile%
FileAppend,%HotList%,%TempFile%
Run,%TempFile%
Return

Open in new window

Regards, Joe
Luis DiazIT consultant

Author

Commented:
Hi Joe,

> To make them meet the buffer structure
I meant the 4 buffer lines to have the information reported in txt file.
Ahk ==>description of ahk

I am going to read again the doc concerning #if case sensitive as it is complicated for me to understand.

Thank you very much for the revised proposal. I am going test it and keep you informed. I don't have access right now to my computer. I am writing this comment from my smartphone.
Luis DiazIT consultant

Author

Commented:
OBdA, thank you very much for your revised proposal. I am going to test it and keep you informed.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
> I meant the 4 buffer lines to have the information reported in txt file.

Ah, thank you for that, now I understand. All you have to do is move the #IfWinActive directive above the comments, like this:

#IfWinActive,ahk_class CabinetWClass
;====================================
;Windows Explorer: copy path
;====================================

+F1::
Send, !hcp
Return
#If

Open in new window

The AutoHotkey code that I posted will work with that structure, and the #IfWinActive and #If directives will also work that way. Regards, Joe
Luis DiazIT consultant

Author

Commented:
Hi Joe,

Concerning #IfWinActive,ahk_class CabinetWClass,
I think that I am going to avoid context-sensitivity as a result I was thinking to revised the various scripts of my AutoHotkey/Hotstring file that use this line
#IfWinActive,ahk_class CabinetWClass
By replacing by:
If (WinActive("ahk_class CabinetWClass"))

Example:
;====================================
;Windows Explorer: copy path
;====================================

+F1::
If (WinActive("ahk_class CabinetWClass"))
  Send, !hcp
Else
  MsgBox,0x1010,Error,your active windows is not windows explorer
Return

Open in new window


Let me know your feedback on this revised approach.

Concerning last proposal. I tested and it works. I was wondering if there is a way to have in front of each AutoHotkey the real keyboard combination equivalent:

Current version displays the following:
#!c::  ==> Run Cmd (line 46)
I was wondering if we can have:
#!c:: (Win+Alt+c) ==> Run Cmd (line 46)

If necessary I will open a new question on this however If we can have the last version on this question it would be great in order to keep the script versioning in the same question.

Thank you for your help.
Luis DiazIT consultant

Author

Commented:
@oBdA: concering last proposal, is there a way to have as new column to display the real keyboard combination by duplicating in your script:
e={$_.Line}}

Open in new window

and replace characters as following:
! should be replaced by Alt
+ should be replaced by Shift
^ should be replaced by Ctrl
# should be replaced by Win

Current version displays the following:
20191212_233349.pngI was wondering if we can have:
A new Keyboard column right after Hotkey column to display
#!c:: (Win+Alt+c) ==> Run Cmd (line 46)

Thank you for your help.
Luis DiazIT consultant

Author

Commented:
I will be out for a while as I have a meeting tomorrow morning GMT time.
As soon as I can, I will test if there are other proposals.
Thank you again for your help.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018
Commented:
Hi Luis,

> If (WinActive("ahk_class CabinetWClass"))
> Let me know your feedback on this revised approach.

Yes, that works fine.

> Concerning last proposal. I tested and it works.

Great news!

> I was wondering if there is a way to have in front of each AutoHotkey the real keyboard combination equivalent:

Sure, no problem.

> #!c:: (Win+Alt+c) ==> Run Cmd (line 46)

Here's revised AutoHotkey code that does it:

+^F6::
TempFile:=A_ScriptDir . "\~hotkeys-hotstrings.txt"
HotID:="::"
HotList:=Line2:=Line3:=Line4:=Line5:=""
LineNum:=0
Loop,Read,%A_ScriptFullPath%
{
  LineNum:=LineNum+1
  Line1:=Line2
  Line2:=Line3
  Line3:=Line4
  Line4:=Line5
  Line5:=A_LoopReadLine
  If (InStr(Line5,"HotID:=")) ; skip if this is the HotID assignment statement
    Continue
  If (InStr(A_LoopReadLine,HotID)) ; skip if this line is not a hotkey/hotstring definition
  {
    If (SubStr(A_LoopReadLine,RegExMatch(A_LoopReadLine,"\S"),1)=";") ; skip if it is commented out
      Continue
    KeyCombo:=StrReplace(Line5,"+","Shift+") ; do this first so we don't catch the other plus signs
    KeyCombo:=StrReplace(KeyCombo,"!","Alt+")
    KeyCombo:=StrReplace(KeyCombo,"^","Ctrl+")
    KeyCombo:=StrReplace(KeyCombo,"#","Win+")
    KeyCombo:=StrReplace(KeyCombo,":",,2)
    HotList:=HotList . Line5 . " (" . KeyCombo . ") ==> " . StrReplace(Line2,";","",1) . " (line " . LineNum . ")`n" ; remove semi-colon and concatenate this hotkey/hotstring to list
  }
}
FileDelete,%TempFile%
FileAppend,%HotList%,%TempFile%
Run,%TempFile%
Return

Open in new window

> If necessary I will open a new question on this

Not necessary.

Sample test output from script above:

+^F6:: (Shift+Ctrl+F6) ==> Display all AutoHotkey/Hotstring in a txt file (line 6)
#!e:: (Win+Alt+e) ==> Run Excel (line 42)
#!p:: (Win+Alt+p) ==> Run PowerPoint (line 57)
#!w:: (Win+Alt+w) ==> Run Word (line 71)
#^a:: (Win+Ctrl+a) ==> Run Programs & Features (line 85)

Open in new window

Regards, Joe
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
Get-Content '.\Whatever.ahk' |
	Select-String -Pattern '^(?!;).*?::' -Context 3,0 |
	Select-Object -Property `
		@{n='HotKey'; e={$_.Line}},
		@{n='Keyboard'; e={'(' + $($_.Line.TrimEnd(':').Replace('+', 'Shift+').Replace('^', 'Ctrl+').Replace('!', 'Alt+').Replace('#', 'Win+')) + ')'}},
		@{n='Command'; e={$_.Context.PreContext[0].Trim('; ')}},
		@{n='LineNumber'; e={$_.LineNumber}} |
	Out-GridView -Wait

Open in new window

Luis DiazIT consultant

Author

Commented:
Thank you for those proposals!
I will test them and keep you informed.
Luis DiazIT consultant

Author

Commented:
Joe,
I tested your proposal and it works! Thank you very much for your help!
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
That's great news, Luis. You're very welcome and thanks to you for letting me know that it works. Regards, Joe
Luis DiazIT consultant

Author

Commented:
oBdA,
Based on your proposal:
https://www.experts-exchange.com/questions/29166455/AutoHotkey-display-the-various-AutoHotkey-Hotstring-reported-in-a-file.html#a42995998
Possible to have the single command version, this will allows me to add it in my AutoHotkey/Hotstring through run command.
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
Get-Content '.\Whatever.ahk' | Select-String -Pattern '^(?!;).*?::' -Context 3,0 | Select-Object -Property @{n='HotKey'; e={$_.Line}}, @{n='Keyboard'; e={'(' + $($_.Line.TrimEnd(':').Replace('+', 'Shift+').Replace('^', 'Ctrl+').Replace('!', 'Alt+').Replace('#', 'Win+')) + ')'}}, @{n='Command'; e={$_.Context.PreContext[0].Trim('; ')}}, @{n='LineNumber'; e={$_.LineNumber}} | Out-GridView -Wait

Open in new window

Luis DiazIT consultant

Author

Commented:
OBdA,
I tested and it works!
Can I defined specific size width on columns of grid-view?
20191214_152117.png
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
Nope, sorry.
Only customization is the title, so you could add something like "-Title 'AHK Command list'" to Out-GridView.
Luis DiazIT consultant

Author

Commented:
True, I can expand the title.
Thank you very much for your help.
Luis DiazIT consultant

Author

Commented:
And a timer to close automatically after a certain time?
Luis DiazIT consultant

Author

Commented:
And sorry I forgot, a bring to front the view?
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
Neither, sorry. It's just a quick GUI tool to display tables.
PS C:\PS> Get-Help Out-GridView

NAME
    Out-GridView

SYNOPSIS
    Sends output to an interactive table in a separate window.


SYNTAX
    Out-GridView [-InputObject <PSObject>] [-PassThru] [-Title <String>] [<CommonParameters>]

    Out-GridView [-InputObject <PSObject>] [-OutputMode <OutputModeOption>] [-Title <String>] [<CommonParameters>]

    Out-GridView [-InputObject <PSObject>] [-Title <String>] [-Wait] [<CommonParameters>]

Open in new window

Luis DiazIT consultant

Author

Commented:
Noted, thank you anyway!
A quick GUI tool but very powerful and user friendly!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial