Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

The popular SciTE-based AutoHotkey Script Editor
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

11 Jan 2023, 11:38

My OS is Windows 11 and at Settings > Apps > Default apps > Choose defaults by file type, .ahk is associated with AutoHotkey Unicode 64-bit. If left like this, then saving in SciTE4AutoHotkey will not apply the file extension. Changing the default app to SciTE4AutoHotkey will allow me to save with the correct file extension, but clicking a file in File Explorer or on the desktop will not launch the script and will open in SciTE4AutoHotkey.

EDIT: Also changing the default app will make scripts that are put in the startup folder to open in SciTE4AutoHotkey.
User avatar
boiler
Posts: 16978
Joined: 21 Dec 2014, 02:44

Re: Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

16 Jan 2023, 00:22

You seem to be confusing opening (running) a script file with editing a .ahk script file. You don’t want to associate the .ahk extension with an editor in the manner you describe because that means it will open (run) by opening the file in your editor instead of running it as an AHK script.

You should only want it to open in your editor when you “Edit” the file, not “Open” it, especially since selecting open is the same as double-clicking it. You might say, “but I double-click .txt files to open them in an editor.” But that’s because .txt files are only meant to be edited, not executed like a script. ”Open” and “Edit” for .txt files are basically is the same thing, but they’re different for scripts.

If you installed SciTE4AutoHotkey correctly, it would have set it up so that it is the default editor for .ahk files (i.e., when you right-click on a file in File Explorer and select “Edit” — not “Open”).
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

16 Jan 2023, 05:45

Okay, I uninstalled and reinstalled while enabling Set as default .ahk file editor:

SciTE4AutoHotkey_Setup 16_01_23 05⦂36⦂22⦂359 AM.jpg
SciTE4AutoHotkey_Setup 16_01_23 05⦂36⦂22⦂359 AM.jpg (49.42 KiB) Viewed 2624 times

I just can't save with the .ahk extension:

Save_a_Copy 16_01_23 05⦂35⦂30⦂042 AM.jpg
Save_a_Copy 16_01_23 05⦂35⦂30⦂042 AM.jpg (85.46 KiB) Viewed 2624 times
User avatar
boiler
Posts: 16978
Joined: 21 Dec 2014, 02:44

Re: Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

16 Jan 2023, 07:02

I don’t have that installed anymore. Are you saying there are no options if you click the dropdown next to “Save as type:”?

It looks like it’s filtering on AHK script files already because the pane above is showing all AHK scripts. Or maybe it’s just showing all files since that’s all you would have in that directory. It also looks like your settings are to not display extensions for known file types, which I hate the fact that that is the Windows default. You might want to change that in the File Explorer settings so you would see the actual .ahk part of the file names.
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

16 Jan 2023, 07:06

Yes:
Attachments
Save_a_Copy 16_01_23 07⦂07⦂49⦂128 AM.jpg
Save_a_Copy 16_01_23 07⦂07⦂49⦂128 AM.jpg (77.71 KiB) Viewed 2592 times
User avatar
boiler
Posts: 16978
Joined: 21 Dec 2014, 02:44

Re: Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

16 Jan 2023, 07:09

I guess someone else will have to help with that, but I suggest making the change I suggested regarding displaying extensions.
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

07 Apr 2023, 00:12

@boiler My solution was:

Code: Select all

if WinWait("Save a Copy ahk_exe SciTE.exe")
Send ".ahk{left 4}"
This only works one time and if I replace WinWait with WinAxtive, I get an error that says that variable hasn't been assigned.

EDIT:

This also works once:

Code: Select all

WinWaitActive "Save a Copy ahk_exe SciTE.exe"
ControlSetText ".ahk", "Edit1"
Send "{left 4}"
Can you tell me why this happens to these scripts?
User avatar
boiler
Posts: 16978
Joined: 21 Dec 2014, 02:44

Re: Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

07 Apr 2023, 01:32

LAPIII wrote: This only works one time
…Can you tell me why this happens to these scripts?
Because you have done nothing to tell it to execute those lines more than once. How many time would you expect the following MsgBox to appear?

Code: Select all

MsgBox "Hello"
If you can see that it would only execute once, why would what you showed be any different other than because you want it to? You have to tell it to execute more than once:

Code: Select all

loop {
	WinWaitActive "Save a Copy ahk_exe SciTE.exe"
	Send ".ahk{left 4}"
	WinWaitNotActive "Save a Copy ahk_exe SciTE.exe"
}

LAPIII wrote: and if I replace WinWait with WinAxtive, I get an error that says that variable hasn't been assigned.
That’s because there is no such function as WinAxtive. There is WinActive, but you shouldn’t use that. It would work but it would be continuously looping instead of only looping after the window appears. You should use WinWait or even better to to use WinWaitActive, but in the loop like above.
User avatar
boiler
Posts: 16978
Joined: 21 Dec 2014, 02:44

Re: Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

07 Apr 2023, 01:37

I snuck in an edit to add WinWaitNotActive or else it will keep sending over and over while the window is there.
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

S

02 Jul 2023, 13:42

Can I add Save File to the loop? I tried using && and AND, but they didn't work.
User avatar
boiler
Posts: 16978
Joined: 21 Dec 2014, 02:44

Re: Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

02 Jul 2023, 15:00

Do you you want it to wait for Save or Save a Copy window? Then leave off the a Copy and it will find either.
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

02 Jul 2023, 15:09

The editor's functions are under File and are the 6th and 7th options. This is what I tried that failed:

Code: Select all

loop {
	WinWaitActive "Save a Copy && Save File ahk_exe SciTE.exe"
	Send ".ahk{left 4}"
	WinWaitNotActive "Save a Copy && Save File hk_exe SciTE.exe"
}
and:

Code: Select all

loop {
	WinWaitActive "Save a Copy AND Save File ahk_exe SciTE.exe"
	Send ".ahk{left 4}"
	WinWaitNotActive "Save a Copy AND Save File ahk_exe SciTE.exe"
}
Save_File 02_07_23 04⦂03⦂27⦂389 PM.jpg
Save_File 02_07_23 04⦂03⦂27⦂389 PM.jpg (80.95 KiB) Viewed 1460 times
User avatar
boiler
Posts: 16978
Joined: 21 Dec 2014, 02:44

Re: Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

02 Jul 2023, 15:15

It doesn’t allow AND like that. As I mentioned above, just make it Save so it will match either Save File or Save a Copy:

Code: Select all

 loop {
	WinWaitActive "Save ahk_exe SciTE.exe"
	Send ".ahk{left 4}"
	WinWaitNotActive "Save ahk_exe SciTE.exe"
}
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Can I be able to save AHK files and to be able to click on one in File Explorer without opening in this app?

09 Mar 2024, 23:03

I came up with this solution because I've had scripts with the word save in it:

Code: Select all

SetTitleMatchMode "RegEx"

loop {																	; writes .ahk in a Save window
	WinWaitActive "Save File|Save a Copy ahk_exe SciTE.exe"
	Send ".ahk{left 4}"
	WinWaitNotActive "Save ahk_exe SciTE.exe"
}

Return to “SciTE4AutoHotkey”

Who is online

Users browsing this forum: No registered users and 103 guests