AutoHotkey Community

It is currently May 26th, 2012, 6:43 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: July 16th, 2005, 12:50 am 
Offline

Joined: June 26th, 2005, 9:43 pm
Posts: 40
Location: Portugal
Imagin I create a format ".hello" for example, and when a format .hello is executed it executes an AHK script [I know how to associate the format to the program, the problem is..], how does the program know what file was executed to execute the AHK script ?!

The idea is, the .hello files will have variables [like a INI file], and the AHK script should read the vars of that file.

[I know how to read the vars from the file, I just want to know how does the script can discover what file were used to execute it [the .hello file]]


::::::::::
When you have .JPG files associated to MS Paint, when I double click the JPG it opens the file with Paint.. and it's exactly this that I want to happen when I execute a .hello file =)

[I hope you ppl understood what I want ^^;;]

_________________
Belial


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2005, 10:12 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Hi,
I never tried this. But you might want to capture the command line parameters that are given to the associated ahk script when you double click that .hello file.
Please have a look at the manual:
"Passing Command Line Parameters to a Script "

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2005, 2:07 pm 
Offline

Joined: June 26th, 2005, 9:43 pm
Posts: 40
Location: Portugal
From AHK's Tutorial:
Quote:
Passing Command Line Parameters to a Script
Scripts support command line parameters. The format is:
AutoHotkey.exe [Switches] [Script Filename] [Script Parameters]

And for compiled scripts, the format is:
CompiledScript.exe [Switches] [Script Parameters]

Switches can be zero or more of the following:
/f or /force -- Launch unconditionally, skipping any warning dialogs.
/r or /restart -- Indicate that the script is being restarted (this is also used by the Reload command, internally).
/ErrorStdOut -- Send syntax errors to stdout rather than displaying a dialog. See #ErrorStdOut for details.

Script Filename can be omitted if there are no Script Parameters. If omitted, it will run (or prompt you to create) AutoHotkey.ini in the current working directory.

Script Parameters can be any strings you want to pass into the script (but any string that contains spaces must be enclosed in double quotes). The script sees incoming parameters as the variables %1%, %2%, and so on. In addition, %0% contains the number of parameters passed (0 if none).

If the number of parameters passed into a script varies (perhaps due to the user dragging and dropping a set of files onto a compiled script), the following example can be used to extract them one by one:

Loop, %0% ; For each parameter:
{
param := %A_Index% ; Fetch the contents of the variable whose name is contained in A_Index.
MsgBox, 4,, Parameter number %A_Index% is %param%. Continue?
IfMsgBox, No
break
}If the parameters are file names, the following example can be used to convert them to their case-corrected long names (as stored in the file system), including complete/absolute path. [requires v1.0.25.14+]

Loop %0% ; For each parameter (or file dropped onto a script):
{
GivenPath := %A_Index% ; Fetch the contents of the variable whose name is contained in A_Index.
Loop %GivenPath%
LongPath = %A_LoopFileLongPath%
MsgBox The case-corrected long path name of file`n%GivenPath%`nis:`n%LongPath%
}


This is interesting and useful. However, I know how to give parameters on "links" [.lnk], but on one other format I have no Idea how it is done [if it is even possible].

Defining a Parameter with the name of the file [the .hello] that was executed, it would end up my problem.

Any ideia how to give the parameter?!

[When u double click a .AHK file u are executing AutoHotkey.exe who reads the .AHK ... in this example .. how does the AutoHotkey.exe knows what .AHK was needed to read ?!]

_________________
Belial


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2005, 2:20 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
I created a file "test.hello"
and I created a script "test.ahk" with the following content
Code:
msgbox, %0%`n%1%

I compiled the test.ahk to a file test.exe.
Then I linked the *.hello file to be opened with the test.exe file.
When I doubleclicked on the *.hello file a message box came up with

Quote:
---------------------------
test.exe
---------------------------
1
C:\Path\test.hello
---------------------------
OK
---------------------------

So, you see, the exe got the path and filename when the .hello file gets doubleclicked. :))

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2005, 2:15 am 
Offline

Joined: June 26th, 2005, 9:43 pm
Posts: 40
Location: Portugal
THANK YOU ^^

It was very simple after all, thanks a lot for your help =P

_________________
Belial


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: dra, rbrtryn and 68 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group