AutoHotkey Community

It is currently May 26th, 2012, 7:27 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: April 30th, 2009, 7:13 pm 
Offline

Joined: January 21st, 2009, 5:49 pm
Posts: 176
Can anyone post an example to get command line params that doesn't use Loop %0%

??

All I'm trying to do is look for an initial optional switch of /q for "quiet mode"

So if the user specifies /q arg1 arg2 arg3

I'll just process arg1... on without prompting
otherwise, prompt on each
or
if there's no args just put up the InputBox


I can't even pick the "/q" off the command line. No idea of it should be a quoted string or what. Really baffling.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 30th, 2009, 7:24 pm 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
perhaps this thread here can help you.

http://www.autohotkey.com/forum/viewtopic.php?t=39791


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 30th, 2009, 7:37 pm 
Offline

Joined: January 21st, 2009, 5:49 pm
Posts: 176
Thanks for the reply. I found this
http://www.autohotkey.com/forum/viewtop ... e+switches

What's totally baffling to me is that
If (0 > 0 && 1 = /q) does not work to pick /q off command line

but

If 0 > 0
If 1 = /q does work. Why must I be tortured like this? jeez!!

So far I've tried 2 versions of Scite using Param thingy in editor to test without compiling scripts. Both version always return blanks at least on Vista. Oh well.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 30th, 2009, 7:58 pm 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
i thought AHK had only problems with backslashes (and only trailing ones) when passed as arguments.. nevertheless it's good to know about this as well.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 30th, 2009, 9:57 pm 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
Would transferring it to a sanely named variable help? You could just start your script with this:
Code:
Arg1 = %1%

And then you can do whatever you want with Arg1 from there.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2009, 1:05 am 
Offline

Joined: January 21st, 2009, 5:49 pm
Posts: 176
ManaUser wrote:
Would transferring it to a sanely named variable help? You could just start your script with this:
Code:
Arg1 = %1%

And then you can do whatever you want with Arg1 from there.


Thanks. I've seen a few ahk guys give that suggestion. It wasn't so much that I couldn't pick off the command line switch as I was baffled by the difficulty of a mere compound If statement. In most other languages, when you do something like
If x < y or not done then yadda yadda

and sometimes it doesn't like the 'not' without parens so you do
If x < y or (not done)

or you do

If (x < y) or (not done)

the point being it probably takes you 30 seconds to try them all until one works. In this here, with the blank returns I wasn't even sure if the Param function in the Scite worked. Just seemed like everything was always blank.

I mean I could have done
if this
if that

sooner but I was trying to understand compound if since I'm likely to use it in the future. Just kind of frustrating. Today I tried to put a hack where I use FileSelectFile instead of that windows browseforfolder piece of crap, to get a folder by telling the user to Alt Right Click the mouse. Works fine if you dump the lines in a script but I can't figure out any useful way of putting it in a separate file of useful functions. Guess the easier thing to do would be have a program that does nothing but get the program you want to run with the folder name, of the command line, do the hack and get the folder name, then use Run passing FolderName as param to the exe that does something!! I quit Perl because of this kind of stuff. :)

For really short quick hotkey I guess I can use it but anything over 2 screens I'll be in straight jacket. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2009, 3:03 am 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
MilesAhead wrote:
If (0 > 0 && 1 = /q) does not work to pick /q off command line

but

If 0 > 0
If 1 = /q does work. Why must I be tortured like this? jeez!!


that's because one is an expression if (with parentheses) and the other is a legacy if

try
Code:
If (0 > 0 && 1 = "/q")

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2009, 4:11 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
engunneer wrote:
Code:
If (0 > 0 && 1 = "/q")

Correct me if I'm wrong, but I don't think you can use the command line variables in an Expression If. Won't they but taken as a literal 0 and 1?

That's why I suggested putting them into variables with more standard names.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2009, 5:37 am 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
you are most likely correct. As usual, I post untested :)

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2009, 3:39 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Variables
AHK Help File wrote:
Although a variable name may consist entirely of digits, this is generally used only for incoming command line parameters. Such numeric names cannot be used in expressions because they would be seen as numbers rather than variables.

P.S. if (expression)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2009, 5:45 pm 
Offline

Joined: January 21st, 2009, 5:49 pm
Posts: 176
ManaUser wrote:
engunneer wrote:
Code:
If (0 > 0 && 1 = "/q")

Correct me if I'm wrong, but I don't think you can use the command line variables in an Expression If. Won't they but taken as a literal 0 and 1?

That's why I suggested putting them into variables with more standard names.


So when I look in the help an see

if 0 < 3 ; The left side of a non-expression if-statement is always the name of a variable.
{
MsgBox This script requires at least 3 incoming parameters but it only received %0%.
ExitApp
}

I'm supposed to intuitively know that I can't use parens?
That's what I mean. Sorry to pick on the language. It can
definitely do some things with hotkeys so easily that I can't just
leave it alone. I think I tried it when it was autoit years ago
because I vaguely remember the IfEqual,, stuff with the commas.

But, an hour of research to type 3 lines of code is definitely a drawback.
Maybe the parser locks you in and there's nothing can be done, but to have

if (0 > 1 or 1 = /q) illegal but
if 0 > 1
if 1 = /q legal is a bit insane.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2009, 6:03 pm 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
Well it is explained in the documentation what the difference between a legacy if and an expression if is, but it's definitely quirky, no one is denying that.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2009, 6:47 pm 
Offline

Joined: January 21st, 2009, 5:49 pm
Posts: 176
ManaUser wrote:
Well it is explained in the documentation what the difference between a legacy if and an expression if is, but it's definitely quirky, no one is denying that.


Yeah, I'm not trying to beat it over the head. I think it would be helpful though, to have more examples of doing common things so that newbies don't get frustrated and discouraged. Command line params is one of the standard and common tasks and likely to be one of the first things a newbie tries to do. To have 3 lines of example is meager. Esp. when you have to deal with such unorthodox rules.

The help could give an example with switches and multiple parameters in a few different scenarios. The less intuitive something is the more examples you need in the help. That's pretty intuitive.

As I say, I would not try to fix Vista to open folders in a separate window by pressing ControlEnter hotkey using Delphi 5. But I can do it in ahk easily like this:

Code:
#IfWinActive,ahk_class CabinetWClass
^Enter::
Gosub, DoOpen
Return
#IfWinActive,ahk_class ExploreWClass
^Enter::
Gosub, DoOpen
Return

DoOpen:
clipboard =  ; Start off empty to allow ClipWait to detect when the text has arrived.
Send ^c
ClipWait, 2  ; Wait for the clipboard to contain text.
Loop, parse, clipboard, `n, `r
{
    run, explorer %A_LoopField%
}
Return


plus a few doodads to have About and other commands in the Tray Menu etc.. so it's just a shame not to make it more accessible. Guess if I get more used to it ... I've just been indoctrinated with all that jazz about encapsulation and I like to make components and functions where this is more attuned to globals with line lables and just all in one file for the most part. So it's disorienting. :)

As example of what I mean, I hate that stupid SHBrowseForFolder thing they give in windows to select a folder. So I did a hack to use the FileOpen dialog, but just prompt the user to AltRightClick the Mouse on a folder. Works great, but there seems no real way to enclose it in a function in a general purpose function file or library. So stuff is more attuned to code snippets than real functions. It's a different way of working I guess.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 4th, 2009, 8:59 am 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
I have not read, because I have not many time left now. just a tipp to get the full commandline without any loop as one string.

Code:
msgbox, % DllCall( "GetCommandLine", "str" )


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2011, 3:10 am 
Offline

Joined: January 21st, 2009, 5:49 pm
Posts: 176
Tuncay wrote:
I have not read, because I have not many time left now. just a tipp to get the full commandline without any loop as one string.

Code:
msgbox, % DllCall( "GetCommandLine", "str" )


Sorry I didn't respond earlier. Thank you for the reply. Too often I forget about the WinAPI. Lots of stuff made easier. :)

_________________
"I don't want to belong to any club that would have me as a member."
- Groucho Marx


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, Google Feedfetcher, joetazz, krajan, over21, RaptorX, rbrtryn, SKAN, Xx7, Yahoo [Bot] and 69 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