Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Associate a File type


  • Please log in to reply
8 replies to this topic
ObiWan
  • Guests
  • Last active:
  • Joined: --
I was wondering if it was possible to associate a new file type to one of my programs. I wanted to be able to create external files so i can periodically have updates but i do not want to put them in the .txt format because people can easily edit it.

adamrgolf
  • Members
  • 442 posts
  • Last active: May 22 2017 09:16 PM
  • Joined: 28 Dec 2006
i think associating a certain extension to a program of your choice can be easily done through the registry, try searching a bit (i've never done it outside of Tools->Folder options)

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

i do not want to put them in the .txt format because people can easily edit it.

They can still easily edit it, even if using a non-standard extension...
Anyway, a typical registry file looks like:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.ow]
@="ObiWanFile"

[HKEY_CLASSES_ROOT\ObiWanFile]
@="ObiWan Custom Format"

[HKEY_CLASSES_ROOT\ObiWanFile\DefaultIcon]
@="C:\\Program Files\\ObiWan\\SpecialScript\\SpecialScript.exe,1"

[HKEY_CLASSES_ROOT\ObiWanFile\shell\open]
@="Open File"

[HKEY_CLASSES_ROOT\ObiWanFile\shell\open\command]
@=""C:\\Program Files\\ObiWan\\SpecialScript\\SpecialScript.exe" "%1""

Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

ObiWan
  • Guests
  • Last active:
  • Joined: --
Sorry but i'm not sure how to use this. Do i save it in ahk format? Or must i go to the registry and edit a file with this?

ObiWan
  • Guests
  • Last active:
  • Joined: --
Oh i am also having a problem with the #Include command. I assumed, as far as i read and understood, that it would include a specified file's contents in the exact position. This it did, while still in the .ahk format meaning i was able to edit the external file and the main script would reflect those changes. But after i compiled the script into and .exe, it no longer works. It is as though when it compiled, the external file's contents were loaded into the main script. Is this how it is supposed to work? or am i just doing something wrong. here is the line i used.

#Include Resources\CC.txt

I also used the full file's path but i got an error in the conversion saying it could not be found.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

Oh i am also having a problem with the #Include command. I assumed, as far as i read and understood, that it would include a specified file's contents in the exact position.

Yes.

This it did, while still in the .ahk format meaning i was able to edit the external file and the main script would reflect those changes. But after i compiled the script into and .exe, it no longer works. It is as though when it compiled, the external file's contents were loaded into the main script. Is this how it is supposed to work?

Yes.
Currently AutoHotkey cannot compile a file dynamically, and beside, a compiled script doesn't need the compiler. So at compile time, ahk2exe just gather the included files in a big script.
You cannot run an uncompiled script with just a compiled script, unless packaging AutoHotkey.exe with it (something similar has been already asked recently, except that user wanted to compile sub-script to get them encrypted).
If possible, just use a plain file and read it.

Sorry but i'm not sure how to use this.

I shown a .reg file, similar to what you get when you export a registry key from regedit.
Three ways to use this info:
1) Just create this file (name it ObiWanFile.reg for example); double-clicking on it (or using AHK's Run command) put its content to the registry (with user prompt for acknowledgment);
2) Generate this file with AHK, changing the paths dynamically, etc. Save it to disk and run it as above;
3) Use this file as blueprint for AHK's registry commands. The [] parts are the keys, the @ marks the default value for this key.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Perhaps the easiest way to do this is to use integrated console commands ASSOC and FTYPE. That way you don't have to mess with Registry witch is in your case good.

This is how to register ahk files (open console and type those):


assoc .ahk=AutoHotKey
ftype AutoHotKey="c:\program files\AHK\Autohotkey.exe" "%%1"

You can run this from console or you can create batch file in AHK and execute it via RUN command:

 PSTR=AutoHotKey
 PEXT=.ahk
 PEXE=c:\program files\AutoHotKey\AutoHotkey.exe

batch=(
assoc %PEXT%=%PSTR%
ftype %PSTR%="%PEXE%" "%%1"
)

FileAppend %batch%, c:\register.bat
RunWait c:\register.bat
FileDelete c:\register.bat

Posted Image

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Oooooh! o.O (discovering new commands)
This can be interesting as they list the keys when used without command line parameter. So we can grep it.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

ObiWan
  • Guests
  • Last active:
  • Joined: --
Thank you.