 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
lingoist
Joined: 05 Oct 2004 Posts: 118 Location: Brasília, Brazil
|
Posted: Sun Oct 17, 2004 4:07 pm Post subject: Associate an extension to my program |
|
|
Hi,
I'd like to know how to associate an extension (*.anc) to my program create with AHK. Would anybody have a tip?
Thanks,
Lingoist.
Last edited by lingoist on Fri Nov 04, 2005 11:42 pm; edited 1 time in total |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Sun Oct 17, 2004 4:55 pm Post subject: |
|
|
Create the file with that ext.
Execute that file. You'll be asked which app should open that type of file.
Assign eg. Notepad/Notepad2/UltraEdit/or any other editor to it.
Select "Always use this ..." & save that setting.
Open Explorer/Tools/Folder Options/File Types and select the *.anc entry from the list. Click "Advanced". Here you can do any specific changes regarding your new file type. If you need any details on HowTo do that, have a lock at AutoHotkey's settings (*.ahk).
Compile
edit
open
run
Or use: File Type Manager [Freeware] which has been recommended here [more...]
 |
|
| Back to top |
|
 |
lingoist
Joined: 05 Oct 2004 Posts: 118 Location: Brasília, Brazil
|
Posted: Sun Oct 17, 2004 11:33 pm Post subject: |
|
|
| I got it, but would you know how to do this with a script in AHK? |
|
| Back to top |
|
 |
dijiyd
Joined: 01 Apr 2004 Posts: 90 Location: Philippines
|
Posted: Sun Oct 17, 2004 11:50 pm Post subject: |
|
|
| I'm guessing that it would require you to manipulate a few registry entries. That could be dangerous, so back-up your registry first. You may want to study up on the subject (where else..) to know more. I haven't done much registry editing so I really can't provide you with more info than this. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10463
|
Posted: Mon Oct 18, 2004 2:17 am Post subject: |
|
|
The below might be of interest because it can convert an existing registry key (such as a subkey of your choice in HKEY_CLASSES_ROOT) to a working script that is capable of recreating that key. You could then modify that script to create a new file association of your own.
http://www.autohotkey.com/forum/viewtopic.php?t=139 |
|
| Back to top |
|
 |
Wingfat
Joined: 23 Aug 2004 Posts: 193 Location: East Bay, California USA
|
Posted: Mon Oct 18, 2004 4:32 pm Post subject: |
|
|
i use this myself:
| Code: |
#A::
clipboard =
send, ^c
clipwait, 100
splitpath, clipboard, , , extension
if extension = ahk
run, "C:\Temp\AutoHotkey\AutoHotkey.exe" "%clipboard%"
Return
|
This will Make WinKey+A run what ever script you have highlighted. Works well for me, you will have to change the Path for your AHK program file. I use this for some of my users systems that they do not have full Admin rights to install or run programs locally on their computer.
 |
|
| Back to top |
|
 |
lingoist
Joined: 05 Oct 2004 Posts: 118 Location: Brasília, Brazil
|
Posted: Thu Oct 21, 2004 2:14 pm Post subject: |
|
|
I'm trying to understand some comands to execute a file, but I don't understand %1 etc after the nome of the program. Could anybody help me? In AutoHotKey, the commands (actions) are:
C:\Arquivos de programas\AutoHotkey\AutoHotkey.exe "%l" %2 %3 %4 %5 %6 %7 %8 %9
Lingoist.
Last edited by lingoist on Fri Nov 04, 2005 11:42 pm; edited 1 time in total |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Thu Oct 21, 2004 2:58 pm Post subject: |
|
|
These are indexed parameters. Like in the BATCH world the first parameter %0% contains the total number of parameters used with an app, %1% the content of the first parameter, %2% the content of the second one, %3% the content ...
1) compile this code to an exe
| Code: | | MsgBox, Number of params used: %0%`n1. param: %1%`n2. param: %2%3. param: %3%4. param: %4%5. param: %5%6. param: %6%7. param: %7%8. param: %8%9. param: %9% |
2) start the exe this way from the command line
My.exe A B C D E F G H I
3) you should get a MsgBox displaying:
Number of params used: 9
1. param: A
2. param: B
3. param: C
4. param: D
5. param: E
6. param: F
7. param: G
8. param: H
9. param: I
This way you're able to transfer a value/variable to a compiled executable.
 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10463
|
Posted: Thu Oct 21, 2004 3:08 pm Post subject: |
|
|
Although I'm a little uncertain about the diffence between "%l" and "%1", the others pass any parameters given to the file as args for the program. I think this only applies when launching the script directly, such as by making a shortcut to it and passing in some args. For example, you could create a shortcut with this in its "target" field:
C:\MyScript.ahk arg1 arg2
The script would receive arg1 and arg2 as it's first two args. The above avoids the need to specify C:\Program Files\... etc. However, it seems that double quotes around args does not work to preserve spaces. If anyone knows a way to improve the registry entry to support args with spaces, please let me know. |
|
| Back to top |
|
 |
savage
Joined: 02 Jul 2004 Posts: 206
|
Posted: Thu Oct 21, 2004 5:11 pm Post subject: |
|
|
An easy way to do this from a script:
(Not tested)
| Code: |
Run, %comspec% /k ftype ancfile="C:\Arquivos de programas\AutoHotkey\AutoHotkey.exe" "%l" "%2" "%3" "%4" "%5" "%6" "%7" "%8" "%9"
Run, %comspec% /k assoc .anc=ancfile
|
Correct me if I'm wrong, but isn't there a %$ parameter in file associations that represents all the parameters?
I thought it safer to put quotes around all the parameters, just to be safe.
If %comspec% doesn't seem to work, replace it with cmd.
I use this method to fix the associations of my file types all the time, especially after textpad, crimson editor, and ultraedit competely screwed them up .
It's a lot safer than mucking about in the registry.
Come to think of it, I'm pretty sure that you only need %1 in there because when you run multiple files at once they each call the command, so it only receives on parameter at a time. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10463
|
Posted: Thu Oct 21, 2004 6:48 pm Post subject: |
|
|
| Quote: | Correct me if I'm wrong, but isn't there a %$ parameter in file associations that represents all the parameters?
I thought it safer to put quotes around all the parameters, just to be safe. | Thanks, I'll look into that. |
|
| Back to top |
|
 |
lingoist
Joined: 05 Oct 2004 Posts: 118 Location: Brasília, Brazil
|
Posted: Fri Oct 29, 2004 4:14 am Post subject: |
|
|
I've partly suceeded in doing it:
My ANC files are based on IniRead/IniWrite functions.
This is a simplified scritp of my program:
| Code: | #SingleInstance FORCE
SetWorkingDir, %A_ScriptDir%
;IT SETS PARAMETERS
param_n=%0% ;how many parameters exist when you run in DOS-prompt: C:\MyFolder\Associate.exe first second third etcetera
param_1=%1% ;the first parameter: first (windows associates automatically to the first parameter)
param_2=%2% ;the second one: second
param_3=%3% ;the third one: third
param_4=%4% ;the forth one: etcetera
;STARTS GUI
Gui, add, edit,
Gui, add, edit,
Gui, add, button, Default, Close
Gui, add, button,, New
Gui, add, button,, Save as
Gui, add, button,, Open
Gui, Show
;TEST PARAMETERS: IF DIFFERENT FROM 0, OPENS THE PARAMETER (FILE)
If param_n > 0
{
; There is a parameter
;file_name is set by the parameter
StringReplace, param_1, param_1, .anc,, all
SplitPath, param_1, param_1_file
msgbox, param_1: %param_1%.anc
msgbox, param_1: %param_1_file%.anc
IniRead, value_box1, %param_1_file%.anc, etc, box1
IniRead, value_box2, %param_1_file%.anc, etc, box2
ControlSetText, Edit1, %value_box1%
ControlSetText, Edit2, %value_box2%
}
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;action of button close
ButtonClose:
GuiClose:
ExitApp
;action of button new
ButtonNew:
ControlSetText, Edit1,
ControlSetText, Edit2,
Return
;action of button save as
ButtonSaveas:
;SAVE AS BOX
FileSelectFile, file_name, 16,, Save as - ANC file, ANC File (*.anc)
if file_name=
MsgBox, The user pressed cancel.
ControlGetText, box1_content, Edit1
ControlGetText, box2_content, Edit2
IniWrite, %box1_content%, %file_name%.anc, etc, box1
IniWrite, %box2_content%, %file_name%.anc, etc, box2
Return
;action of button open
ButtonOpen:
;OPEN FILE BOX
;file_name is set by the user
FileSelectFile, file_name, 3,, Open - ANC file, ANC File (*.anc)
if file_name=
MsgBox, The user pressed cancel.
StringReplace, file_name, file_name, .anc,, all
IniRead, value_box1, %file_name%.anc, etc, box1
IniRead, value_box2, %file_name%.anc, etc, box2
ControlSetText, Edit1, %value_box1%
ControlSetText, Edit2, %value_box2%
Return
|
You'll have your file open when you associate it in Windows Explorer. I still do not know how to do it through Registry and all that stuff.
Special Thanks to Bobo and Chris, (By the way, Bobo in my country means moron!! Sorry...)
Lingoist
Last edited by lingoist on Fri Nov 04, 2005 11:43 pm; edited 1 time in total |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Fri Oct 29, 2004 7:57 am Post subject: |
|
|
| Quote: | | Bobo in my country means moron!! Sorry...) |
I love it. Check this out: [Here] Btw. I hate his music
What's your country ? |
|
| Back to top |
|
 |
dijiyd
Joined: 01 Apr 2004 Posts: 90 Location: Philippines
|
Posted: Fri Oct 29, 2004 9:42 am Post subject: |
|
|
Whoa... he's probably from the philippines. If not, well, bobo means something like stupid here too. Don't worry, I don't think so.  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|