DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Help with autohotkey: Command line switches  (Read 17,712 times)

wreckedcarzz

  • Still lurking. Still an anthro.
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,629
    • Participated in NANY Challenge Twice
    • Coding Snacks
    • Furry Fandom Badge - Furry Fandom
    • Linux User
Help with autohotkey: Command line switches
« on: February 18, 2008, 07:06 AM »
I am having trouble figuring out how to add support for command line switches for AHK programs (completed EXEs). I have googled over and over again, searched the AHK forum and documentation, and I can't find anything on it anywhere. I know it can be done due to Skrommel's BatteryRun.

Can anyone help me?

-Brandon

jgpaiva

  • Artificial Idiocy
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • Cody Award
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Portugal Inhabitant
    • Linux User
Re: Help with autohotkey: Command line switches
« Reply #1 on: February 18, 2008, 07:52 AM »
Well, that's easy.
Code
NumberOfArguments = %0%

FirstArgument = %1%
SecondArgument = %2%
ThirdArgument = %3%
I recommend using this method of extracting the arguments to named variables, since '0','1','2' and '3' are pretty crappy names for variables!

wreckedcarzz

  • Still lurking. Still an anthro.
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,629
    • Participated in NANY Challenge Twice
    • Coding Snacks
    • Furry Fandom Badge - Furry Fandom
    • Linux User
Re: Help with autohotkey: Command line switches
« Reply #2 on: February 18, 2008, 07:54 AM »
So like

Code
NumberofArguments = MyArgumentAmount

MyAction1 = /action1
MyAction2 = /action2

correct?

EDIT: Or do I switch those across the equal sign?

wreckedcarzz

  • Still lurking. Still an anthro.
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,629
    • Participated in NANY Challenge Twice
    • Coding Snacks
    • Furry Fandom Badge - Furry Fandom
    • Linux User
Re: Help with autohotkey: Command line switches
« Reply #3 on: February 18, 2008, 08:32 AM »
Ah, I figured it out. Thanks a lot for that- it was driving me mad! :)

wreckedcarzz

  • Still lurking. Still an anthro.
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,629
    • Participated in NANY Challenge Twice
    • Coding Snacks
    • Furry Fandom Badge - Furry Fandom
    • Linux User
Re: Help with autohotkey: Command line switches
« Reply #4 on: February 18, 2008, 09:03 AM »
Apparently, I didn't quite get it working- it only runs the top item in the list. Can someone take a look at this and explain to me how to get command2 and 3 to show their message boxes? I could only get command to work, but then it would run command2 also. And now nothing works- I am totally lost. :-[

Help, anyone? :tellme:

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: Help with autohotkey: Command line switches
« Reply #5 on: February 18, 2008, 11:16 AM »
I'm not sure what you're trying to get achieved but i think this is what you're looking for:
Code
mycommand=%1%
myothercommand=%2%
myotherothercommand=%3%

If mycommand = 1
{
MsgBox, success
}
else

If myothercommand = 1
{
MsgBox, failure
}
else
If myotherothercommand = 1
{
MsgBox, nothing
}

ExitApp

then call it like this:

  • argumenttest 1
  • argumenttest 0 1
first one will show success, second one failure

« Last Edit: February 18, 2008, 11:19 AM by justice »

wreckedcarzz

  • Still lurking. Still an anthro.
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,629
    • Participated in NANY Challenge Twice
    • Coding Snacks
    • Furry Fandom Badge - Furry Fandom
    • Linux User
Re: Help with autohotkey: Command line switches
« Reply #6 on: February 18, 2008, 05:49 PM »
Ah, OK. I think I understand now. I was messing up the parameters and then messed up the code. :P

EDIT: I am still lost, it keeps launching all the options at once. I am going to keep messing with the code to see what I am doing wrong.
« Last Edit: February 18, 2008, 06:16 PM by wreckedcarzz »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Re: Help with autohotkey: Command line switches
« Reply #7 on: April 30, 2009, 05:43 PM »
I have to say I never had such a struggle trying to get a switch off a command line.  Then to make it even more fun the Scite param passing tool in the editor is broken!!! Sheesh!!

All I'm trying to do is loop through the params and if the first is
/q do "quiet mode" but I can't even detect the /q.  It's really bizarre.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Re: Help with autohotkey: Command line switches
« Reply #8 on: April 30, 2009, 06:08 PM »
seems like the only method that works at all is
Loop %0%

anything else, the value is blank.  really weird

wr975

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 369
    • Coding Snacks
Re: Help with autohotkey: Command line switches
« Reply #9 on: April 30, 2009, 06:57 PM »
Here's my version. ;) (Edited to a simplier version.)

Code
loop
{
	switch := %a_index%
	if switch =
		break

	If switch = /h
		msgbox, Command line parameter /h detected

	If switch = /help
		msgbox, Command line parameter /help detected

	If switch = /hidden
		msgbox, Command line parameter /hidden detected
}

Command line switches work in any order. Example:
scriptname /h
scriptname /h /hidden
scriptname /hidden /help /h
« Last Edit: May 01, 2009, 09:27 AM by wr975 »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Re: Help with autohotkey: Command line switches
« Reply #10 on: April 30, 2009, 09:20 PM »
Thanks for the reply.  What was really throwing me is the funky "left side" rule.
if 0 > 1    the 0 is on the "left side" so it's a variable name but

if (0 > 1  &&  1 = /q)

to me '1' should be on the "left side" but apparently it isn't.  Really a struggle
to do any compound if statement

so finally I just did

if 0 >1
  if 1 = /q  and it works.  I can't believe it

Original address: https://www.donationcoder.com/forum/index.php?topic=12349.0