Script "open with" issues Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ben the Coder

Script "open with" issues

Post by Ben the Coder » 17 Aug 2022, 10:58

Hi,
I have a script (a text editor) and I want to be able to select "open with" in the Windows file menu, then click on the compiled version of my script.
However, my script does not recognize this and will just open the text editing window, not the file.
I feel as though this problem will be difficult to solve, however, I am a beginner with AHK so I'm still really discovering how the syntax works.
Thanks,
Ben ;)

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Script "open with" issues

Post by mikeyww » 17 Aug 2022, 11:04

The idea of "open with" is that you open the current selection or file (not a different one) with a specified program.

I imagine that you could use your text editor to open the uncompiled script with AutoHotkey.exe. To use the compiled version, you could use an approach that identifies the script name from the Window title, appends that to the compiled file's path, and then uses Run to execute the script. Your compiled script may or may not match what is shown in the text editor. If needed, the script can also be compiled during the process.

Ben the Coder

Re: Script "open with" issues  Topic is solved

Post by Ben the Coder » 17 Aug 2022, 11:08

I'm not sure what you mean.
Could you show an example?
Sorry!

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Script "open with" issues

Post by mikeyww » 17 Aug 2022, 11:12

Code: Select all

#IfWinActive ahk_exe notepad.exe
F3::
SoundBeep, 1500
WinGetTitle, title
If FileExist(compiled := A_ScriptDir "\" RegExReplace(title, "\.ahk.*", ".exe"))
 Run, %compiled%
Else MsgBox, 48, Error, File not found.`n`n%compiled%
Return
#IfWinActive
Last edited by mikeyww on 17 Aug 2022, 11:21, edited 2 times in total.

Ben the Coder

Re: Script "open with" issues

Post by Ben the Coder » 17 Aug 2022, 11:19

I get it now.
I'll try it out. :)

Ben the Coder

Re: Script "open with" issues

Post by Ben the Coder » 20 Aug 2022, 19:57

Sorry, but I just tried that now and it doesn't work!
I've modified it to be:

Code: Select all

#IfWinActive ahk_exe TexType.ahk ;I've changed it from Notepad.exe to TexType.ahk since my editor is called TexType.
F3::
SoundBeep, 1500
WinGetTitle, title
If FileExist(compiled := A_ScriptDir "\" RegExReplace(title, "\.ahk.*", ".exe"))
 Run, %compiled%
Else MsgBox, 48, Error, File not found.`n`n%compiled%
Return
#IfWinActive
Can you tell me what I have to change?
P.S. I've upgraded to AHK V2, so would that help? I noticed that the #IfWinActive command has been discontinued, so is there an alternative on V2?

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Script "open with" issues

Post by mikeyww » 20 Aug 2022, 20:08

It's confusing as to what you are trying to do.
I have a script (a text editor) and I want to be able to select "open with" in the Windows file menu
Where is the Windows file menu?
What are you trying to open?
Where is the program with which you are trying to open another file?

Are you simply trying to modify the Windows context menu in a way that has nothing to do with AHK coding?

Or: are you trying to figure out how to use an argument passed to your script on the command line?

In addition to the answers, a step-by-step example might help.

https://www.autohotkey.com/docs/Scripts.htm#cmd_args
Incoming parameters, if present, are stored as an array in the built-in variable A_Args, and can be accessed using array syntax. A_Args[1] contains the first parameter.

Post Reply

Return to “Ask for Help (v1)”