Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

AutoHotkey script: how to know which AutoHotkey scripts I use the most

Hello experts,
I have multiple AutoHotkey scripts in one single file. Please find bellow an exemple: 
The idea is to run an AutoHotkey script without affecting performance of my computer and check which are the one's that I use the most based on a certain period.
The objective of this script is to:

-Check which are the AutoHot script that I use the most.
-Review my compiled file if I need to keep an other file the AutoHotkey script that I don't use anymore.

#NoEnv ; avoid checking empty variables to see if they are environment variables
#SingleInstance Force ; replace old instance immediately
SetBatchLines,-1 ; run at maximum speed
SendMode Input ; faster and more reliable

Open in new window

;====================================
;INSTRUCTIONS
;====================================
; Win => #, Alt => !, Control => ^, Shift => +


;====================================
;SciTE4AutoHotkey KEY SHORCTUS
;====================================


;Toogle bookmark Search Tab: Ctrl + F2
;Go To previous bookmark Shift + F2
;Clear bookmark Alt + S + C


;====================================
;VARIABLES
;====================================
Excel32:="C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE"
Excel64:="C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE"


;====================================
;Run Cmd
;====================================


#!c::
If !(A_IsAdmin) ; you are not admin
{
  Try Run,*RunAs %comspec% /k
  Catch
    MsgBox,4144,Error,Run As Admin failed
  Return
}
Else ; you are already admin
{
  Try Run,%comspec% /k
  Catch
    MsgBox,4144,Error,Run (already As Admin) failed
  Return
}


;====================================
;Run Powershell
;====================================


#!p::
If (FileExist(Powershellexe))
{
  Run,%Powershellexe%
  Return
}
Else
{
  MsgBox,4112,Fatal Error,%Powershellexe% does not exist on your system.
}
Return


;====================================
;Run Chrome
;====================================


#!h::
Run, C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
Return

Open in new window

Regards,
Luis.


Avatar of arnold
arnold
Flag of United States of America image

A suggestion if possible, add to each section a read in writeout updated count.

Hi Luis,
This is an interesting issue. There's nothing built into AutoHotkey that does it, so you'd have to develop a custom solution. I'll give it some thought during the next few days (arnold's suggestion is a good one). On a side note, I hope that you are recovering quickly from the surgery. Regards, Joe
ASKER CERTIFIED SOLUTION
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luis Diaz

ASKER

Hi Joe,
Thank very much for this excellent solution proposal. I left the hospital today and I have just arrived at home 25 minutes ago.
I will test your incredible proposal and will let you know during the next few days.

Regards,
Luis.
Hi Luis,
I'm very glad to hear that you are home from the hospital. I'm wishing you a speedy and full recovery. Of course, your health is #1...there's no rush on this...whenever you feel up to working on it will be fine. All the best, Joe
Hello Joe,
I made a video to discribe the test of your solution proposal reported at:
Solution proposal
Let me know if you are able to watch the video.
Regards,
Luis.
video1091052560.mp4
Hi Luis,

Your video shows that you put the folder name between the quote marks, not the file name. You did this:

InputFile:="C:\Users\luis-\Documents\5.Prog\2.Autohot-Vbs-Cmd-Ps\2.1Autohotkeys"

Open in new window

You should have done this:

InputFile:="C:\Users\luis-\Documents\5.Prog\2.Autohot-Vbs-Cmd-Ps\2.1Autohotkeys\LD-autohotkey.ahk"

Open in new window

Regards, Joe
Noted Joe. I am watching golf swing serie on Netflix with my father. As soon as I finish one chapter I will re do properly the test as recommended.
Regards,
Luis.
Sounds good...no rush.
Hi Joe,
I was able to create LD-autohotkey_Counts.ahk
Once I added the function to generate the count, I have the following error message:
User generated imageThank you for your help.
Regards,
Luis.
The error you're getting is unrelated to my code. You have a Case statement on line 2604, and other Case statements on 2606, 2608, and 2610. They must be enclosed in a Switch statement...that's what the error message is telling you. What does your original script have at the ButtonSendEEBracketStringOK label?
Hi Joe,
This AutoHotkey script was created in order to avoid click on Experts Exchanges buttons. I don't use it anymore as a result I am going to remove it from my reference LD-autohotkey.ahk file.
I attached the script and another related to it as I am not able to properly adjust the code style option and add it to this post.
Regards,
Luis.
send-ee-brackets-20230309_051345.txt
OK, so it seems that these three lines were missing:

Gui,Destroy
Switch EEBracketStringOption
{

Open in new window

With that cleared up, where do things stand now on your effort to create the LD-autohotkey_Counts.ahk file?
Hello Joe,
I don't understand where should I add those three lines:
User generated imageI removed this script in the meantime. Based on your feedback I will review it.
Gosub,IncrementUseCount was added to the whole script (except to variables, functions, and subrutines).
Now that I am trying to launch Ld-autohotkey.ahk, I have the following issue:
User generated imageIf you could provide advice on this, it would be great. If not I will comment the AutoHotkey script or simply remove it.
I attached the AutoHotkey script related to the issue that I am having.
Regards,
Luis.
List-files-and-folders-attributes_20.txt
I don't understand where should I add those three lines
Your post where it has the error messasge "Case/Default must be enclosed by a Switch" shows this:

User generated image
Your post after that shows this:

User generated image
Do you see the difference?
Ok, now I see the difference.
Thank you Joe.
Hello Joe,
Just to let you know that I was able to run the AutoHotkey script as recommended.
User generated imageIt works perfectly!
I do beleive that it can be even better if we can have execution dates the initial/end date and the description of the AutoHotkey script at the count file: HotkeysCounts.ini
Example: #+w=1 (count)=>Run WhatsApp. (Execution date: Initial date: 10/03/2023, 19:00PM End date: 10/03/2023, 19:10PM)
For the moment the script is excellent, the comment mentioned above are just ideas and thoughts.
Have an excellent end of day and thank you again to share your expertise which is extremly high!
> It works perfectly!

Great news! Thanks for posting the HotkeysCounts.ini file...very helpful to see that!

> description of the AutoHotkey script at the count file

That can be done because of your excellent discipline in creating your hotkeys and hotstrings (in fact, code from your +^F6 hotkey can be utilized, since Line2 is the description).

> execution dates the initial/end date

I don't know what you mean by initial date and end date. You gave this example:

Initial date: 10/03/2023, 19:00PM
End date: 10/03/2023, 19:10PM

What are those dates/times? How do those dates/times relate to the hotkey firing? For example, let's say you press ^!b. What is the initial date? What is the end date?
Hi Joe,
First, thank you for those kind words. "Discipline never hurts".
>What are those dates/times? How do those dates/times relate to the hotkey firing? For example, let's say you press ^!b. What is the initial date? What is the end date?
Let me explain what I mean by those dates.
Suppose that I am going to run/execute ^!b::=>"Run WhatsApp application" AutoHotkey script:
At: 20h34PM Colombian Time.
User generated imageThen I run/execute the same AutoHotkey script 2 hours after.
At: 22h34PM Colombian time.
I expect to have this information in the .ini file.
In short, the initial date will be the first date related to date/time execution of the AutoHotkey script. The final date is the most recent date related to the date/time execution. Final/recent date is dynamic as it changes based on the run/execution of the AutoHotkey script. Initial date is static as it will not changes. It will be reported one time and voilà.
If it is not clear, do not hesitate to ask.
Regards,
Luis.
I forgot to let you know that I am agree to have the AutoHotkey description information only at +^F6:: AutoHotkey script.
As we say in french:
Trop d'information tue l'information.
Regards,
Luis.
> If it is not clear

It is clear now...thanks for explaining.

I don't know how difficult those enhancements will be...either the description or the dates. The methodology of using IniRead and IniWrite to do the counting may make those enhancements tough to do. I'll give it some thought, but no promises.
Since Joe solves problems. it sounds as though you are effectively looking for a transactional type log

Potentially after thetransaction log is build your processing of the log will get you the total data.

A counthet had to maintain info. This does not each item need only echo out date, time and the macro event classifier if there are two types.
Hi Luis,

I enhanced the code with your request for the date/time stamps. You asked for this format:

Initial date: 10/03/2023, 19:00PM
End date: 10/03/2023, 19:10PM

Note that 19:00 and PM represent inconsistent date formats, i.e., 19:00 is so-called 24-hour format and normally does not have the AM/PM indicator. If you want AM/PM, which is so-called 12-hour format, the time would be 7:00PM. So, let me know which you want:

(1) standard 24-hour format (19:00)
(2) standard 12-hour format (7:00PM)
(3) combination of them (19:00PM)

I already implemented (2), but could change it to (1) or (3) if you prefer. Here are sample results from my test runs with (2):

!^F3=1 Initial date: 13/03/2023, 8:49PM End date: 13/03/2023, 8:49PM
!^F3=2 Initial date: 13/03/2023, 8:49PM End date: 13/03/2023, 8:50PM
!^F3=3 Initial date: 13/03/2023, 8:49PM End date: 13/03/2023, 8:51PM

Regards, Joe

P.S. Haven't attacked your Description request yet.
Hi Joe,

On your last comment you cover the various requirements of what I am looking for. I am not in a rush and in particular now that I am doing a professional break following my surgery.
Concerning this aspect and on a side note, yesterday my orthopedist withdraws the VAC Vacuum Assisted closure to my foot. The VAC was used to accelerate scaring process of my foot. I feel thinner and I gain on autonomy.
Next week I would have a medical meeting with my infectologist. He will analyse recent blood exams and if everything is ok, he will authorize me to go to the mall to drink a coffee etc... (On Starbucks Bogotá for example😁), perform physiotherapy and do it a normal life with crutches.
Regards,
Luis.
Hi Luis,

First and foremost, I'm glad to hear that you're making progress on your medical recovery.

I completed the last piece of your requirements...the Description, which I placed at the end of the line, after the new Initial date and End date items (I went with standard 12-hour format for those date/time fields).

I tested it here with Excel, PowerPoint, and Word hotkeys...worked perfectly. Here's what the HotkeysCounts.ini looked like after the tests:

[Counts]
!^F3=4 Initial date: 14/03/2023, 5:32PM End date: 14/03/2023, 5:41PM Run PowerPoint
!^F4=2 Initial date: 14/03/2023, 5:34PM End date: 14/03/2023, 5:42PM Run Word
!^F2=3 Initial date: 14/03/2023, 5:35PM End date: 14/03/2023, 5:43PM Run Excel

The new code is backward compatible with the old code, that is, you can leave the current HotkeysCounts.ini as is. The new code will automatically fix the line the next time that you use a hotkey...it will increment the count and add the three new fields (Initial date, End date, Description). Of course, it can't know the actual date/time when you first hit the hotkey, so it uses the current date/time for that.

Also, the new code will automatically change the Description of a hotkey in the HotkeysCounts.ini file if you change its Description in your main AutoHotkey hotkeys/hotstrings file. It will make the change the next time you hit the hotkey after editing and re-running your main AutoHotkey hotkeys/hotstrings file.

How does this sound? Anything I missed? Regards, Joe
Hi Joe,

Based on your last comment you cover the various requirements. Nothing missed everything covered.
Thank you again for your help and your chaleureux message qui me booste d'énergie (french message).

Regards,
Luis.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Joe,

Thank you very much for this proposal.
I will do my best to test your proposal  the 16 of march 2023 (afternoon).

Regards,
Luis.
You're very welcome, Luis. It works perfectly here on a 2020 version of your main AutoHotkey hotkeys/hotstrings file, and I'm looking forward to hearing your results on the current version of that file.
Noted Joe. Thank you again for your help.
Hi Joe,

I was unable to test your proposal today. Tomorrow should be the day.

Regards,
Luis.
No rush, Luis, do it whenever it's convenient for you. Regards, Joe
Hello Joe,

It works perfectly and beatifuly. The following screenshot confirms that.
User generated imageYou know what should be great? To have exactly the same following script for HotkeysCounts.ini

;====================================
;Open AutoHotkey file
;====================================
SciTE1:="C:\Program Files\AutoHotkey\SciTE\SciTE.exe"
SciTE2:="C:\Program Files (x86)\AutoHotkey\SciTE.exe"
#If (!WinActive("ahk_exe excel.exe") and (!WinActive("ahk_exe SciTE.exe") and (!WinActive("ahk_exe powerpnt.exe") and (!WinActive("ahk_exe winword.exe")))))
+F2::
Gosub,IncrementUseCount
AhkFile:=A_ScriptFullPath
If (FileExist(SciTE1))
  Run,"%SciTE1%" "%AhkFile%"
Else
If (FileExist(SciTE2))
  Run,"%SciTE2%" "%AhkFile%"
Else
  MsgBox,4112,Error,Neither SciTE exists on your system.
Return
#If

Open in new window

If need I can create another question.
Regards,
Luis.
Hi Luis,

Thanks for the screenshot showing that it works...great to see!

There's no need for a new question. Here's code for a hotkey to open the HotkeysCounts.ini file:

;====================================
;Open HotkeysCounts.ini file
;====================================

#^h:: ; I made the hotkey Win+Ctrl+H - as always, make it whatever you want
Gosub,IncrementUseCount
If (FileExist(HotkeysCountsFile))
  Run,"%HotkeysCountsFile%" ; this opens the file in the program that owns the INI file type
Else
  MsgBox,4112,Error,HotkeysCountsFile does not exist - this should never happen
Return

Open in new window

Btw, the code in your last post is NOT in your standard format. It should start like this:

#If (!WinActive("ahk_exe excel.exe") and (!WinActive("ahk_exe SciTE.exe") and (!WinActive("ahk_exe powerpnt.exe") and (!WinActive("ahk_exe winword.exe")))))
;====================================
;Open AutoHotkey file
;====================================

+F2::
<rest of the code here>

Open in new window

Remember, our code relies on this: when a line is a hotkey (or a non-auto-replace hotstring), the third line preceding it is the Description. Note that you don't need the SciTE1 and SciTE2 assignment statements there because they're already in your VARIABLES section (at least, they were in 2020...I presume they're still there). Regards, Joe
Hello Joe,

You are totally right in order to simplify I sent you a part of the code instead of sending you the whole .ahk file (LD-autohotkey.ahk) that I use every day with an amazing hapiness. Next time what I will do for this type of situation is to send you LD-autohotkey.ahk to avoid this kine of mistake from my part.
Open HotkeysCounts.file AutoHotkey script proposed works perfectly!

Thank you for your help and have an excellent weekend.

Regards,
The following image is a complementary of my last comment reported:
HERE

User generated image
> Open HotkeysCounts.file AutoHotkey script proposed works perfectly!

Glad to hear it!

> The following image

Something I've been meaning to say for a while...the images that you post are blurry, making them hard to read. I don't know how you capture and manipulate screenshots, but you should look into methods to get better quality. For example, here's a screenshot that I captured with the PrintScreen key and cropped with IrfanView:

User generated image
It's of the same code that is on the left side of your screenshot above. Compare the quality of the two images.

Regards, Joe
Hi Joe,
Thank you for this advice related to PrintScreen. I will download it and buy it if necessary.
I use greenshot.
Regards,
Luis.
Hi Luis,

First, there's nothing to buy. PrintScreen is not a program...it is simply a key that is on every keyboard. It may be marked PrtSc, PrntScn, PS, or something similar. Pressing it causes a screenshot of the monitor (all monitors in a multi-monitor configuration) to be placed on the clipboard. Then simply pasting it (Ctrl+V) into IrfanView (free!), or whatever imaging program you use, allows easy editing of it, such as cropping.

Second, I'm sure Greenshot can produce better quality images. I don't use it, so can't help you, but it has a good reputation and probably has a Quality setting for its JPG and PNG files (I see that the last one you posted is a PNG, which is a good choice...it is what I typically use for screenshots). Regards, Joe
Ah, do you mean the following Windows built-in tool:
User generated imageOk, I am going to make some research to improve the quality of PNG or JPEG images using Greenshot.
Thank you again.

Regards,
Luis.
> Ah, do you mean the following Windows built-in tool

No. I'm not talking about a software tool. I'm talking about a (hardware) key on the keyboard:

User generated image
That said, the tool that you posted should work well...the icon looks like the Snipping Tool, which is built into W10 and W11, although it was recently updated/replaced by the Snip & Sketch tool. Regards, Joe
Noted Joe, detailed and accurate explanation as always!