Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 02, 2016, 02:12:41 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Help with autohotkey: Command line switches  (Read 8688 times)

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,623
    • View Profile
    • Donate to Member
Help with autohotkey: Command line switches
« on: February 18, 2008, 01:06:57 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

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: Help with autohotkey: Command line switches
« Reply #1 on: February 18, 2008, 01:52:00 AM »
Well, that's easy.
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

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,623
    • View Profile
    • Donate to Member
Re: Help with autohotkey: Command line switches
« Reply #2 on: February 18, 2008, 01:54:40 AM »
So like

NumberofArguments = MyArgumentAmount

MyAction1 = /action1
MyAction2 = /action2

correct?

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

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,623
    • View Profile
    • Donate to Member
Re: Help with autohotkey: Command line switches
« Reply #3 on: February 18, 2008, 02:32:57 AM »
Ah, I figured it out. Thanks a lot for that- it was driving me mad! :)

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,623
    • View Profile
    • Donate to Member
Re: Help with autohotkey: Command line switches
« Reply #4 on: February 18, 2008, 03:03:08 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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: Help with autohotkey: Command line switches
« Reply #5 on: February 18, 2008, 05:16:30 AM »
I'm not sure what you're trying to get achieved but i think this is what you're looking for:
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, 05:19:20 AM by justice »

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,623
    • View Profile
    • Donate to Member
Re: Help with autohotkey: Command line switches
« Reply #6 on: February 18, 2008, 11:49:42 AM »
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, 12:16:20 PM by wreckedcarzz »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,275
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: Help with autohotkey: Command line switches
« Reply #7 on: April 30, 2009, 12:43:56 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,275
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: Help with autohotkey: Command line switches
« Reply #8 on: April 30, 2009, 01:08:35 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
    • View Profile
    • Donate to Member
Re: Help with autohotkey: Command line switches
« Reply #9 on: April 30, 2009, 01:57:26 PM »
Here's my version. ;) (Edited to a simplier version.)

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, 04:27:45 AM by wr975 »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,275
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: Help with autohotkey: Command line switches
« Reply #10 on: April 30, 2009, 04:20:32 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