| View previous topic :: View next topic |
| Author |
Message |
MilesAhead
Joined: 21 Jan 2009 Posts: 86
|
Posted: Thu Apr 30, 2009 6:13 pm Post subject: command line params without Loop %0% ?? |
|
|
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. |
|
| Back to top |
|
 |
badmojo
Joined: 11 Nov 2005 Posts: 202
|
|
| Back to top |
|
 |
MilesAhead
Joined: 21 Jan 2009 Posts: 86
|
Posted: Thu Apr 30, 2009 6:37 pm Post subject: |
|
|
Thanks for the reply. I found this
http://www.autohotkey.com/forum/viewtopic.php?t=43520&highlight=command+line+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. |
|
| Back to top |
|
 |
badmojo
Joined: 11 Nov 2005 Posts: 202
|
Posted: Thu Apr 30, 2009 6:58 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 1121
|
Posted: Thu Apr 30, 2009 8:57 pm Post subject: |
|
|
Would transferring it to a sanely named variable help? You could just start your script with this:
And then you can do whatever you want with Arg1 from there. |
|
| Back to top |
|
 |
MilesAhead
Joined: 21 Jan 2009 Posts: 86
|
Posted: Sun May 03, 2009 12:05 am Post subject: |
|
|
| ManaUser wrote: | Would transferring it to a sanely named variable help? You could just start your script with this:
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.  |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 8255 Location: Maywood, IL
|
Posted: Sun May 03, 2009 2:03 am Post subject: |
|
|
| 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")
|
_________________
(Common Answers) |
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 1121
|
Posted: Sun May 03, 2009 3:11 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 8255 Location: Maywood, IL
|
Posted: Sun May 03, 2009 4:37 am Post subject: |
|
|
you are most likely correct. As usual, I post untested  _________________
(Common Answers) |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Sun May 03, 2009 2:39 pm Post subject: |
|
|
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) |
|
| Back to top |
|
 |
MilesAhead
Joined: 21 Jan 2009 Posts: 86
|
Posted: Sun May 03, 2009 4:45 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 1121
|
Posted: Sun May 03, 2009 5:03 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
MilesAhead
Joined: 21 Jan 2009 Posts: 86
|
Posted: Sun May 03, 2009 5:47 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 1886 Location: Germany
|
Posted: Mon May 04, 2009 7:59 am Post subject: |
|
|
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" ) |
|
|
| Back to top |
|
 |
MilesAhead
Joined: 21 Jan 2009 Posts: 86
|
Posted: Tue Jun 14, 2011 2:10 am Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
|