Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run QM Code from command line without creating macros
#1
QM Code Evaluation from the Command Line

Update: Made the instructions more readable. Made the improvement suggested by Gintaras (second post of this thread). Added reuse tip.

I've gotten a lot of use out of this technique, so I thought I'd share it.

This allows you to execute QM code on the fly, from the console or Start->Run or any other command line you have access to (this works very well with lsxcommand for litestep or the broam box plugins for bbLean). If QM isn't running, it'll start then exit as soon as it finishes.

This is great for quick "one-timer" operations that you don't want to make a whole macro for. Say you want to hide a Notepad window, just type:

Code:
Select All      Help
q hid "Notepad"

and its done!

You're basically just putting a 'q' before your code, and you can have multiple commands by ending each statement with a semicolon (;) like this:

Code:
Select All      Help
q mes "Hello there!"; mes "Have a nice day.";

Getting it to work is actually pretty simple, too. Just create a function called "Eval" and paste the following:

Code:
Select All      Help
wait 0 H mac(newitem("temp_macro" _command "temp_macro_template" "" "\User\Temp" 1))

Now open a text editor and paste the following:

Code:
Select All      Help
@ECHO OFF
"C:\Program Files\Quick Macros\qmcl.exe" E M "Eval" C %*

Note 1: You may need to adjust the path to qmcl.exe

Note 2: The %* variable works in Win2k and XP, but older versions of windows may have to do something different, like "%1 %2 %3..." or SHIFT statements. Google "win9x batch file parameters" for more info.

Now save the file as "q.bat" and in your C:\WINNT\ folder.

If something goes wrong, it's easy to know which part broke:
- If you get a windows or console error indicating that 'q' cannot be found or isn't recognized, your batch file is not in the right place. Make sure it's in a directory specified in your environment PATH so that the batch file can be executed anywhere.
- If it doesn't mention 'q' but says 'the system cannot find the path specified" or "qmcl.exe is not recognized," then you gave the wrong path to qmcl.exe in the q.bat file.
- If QM it runs but nothing happens, check your QM console. One of 2 things could be wrong, and it'll let you know. Either the Eval macro wasn't found, or there was something wrong with the code you tried to run.

TIP: If you want to be able to easily rerun the last code you sent, just create a macro that calls temp_macro (mac "temp_macro") and give it whatever trigger you like.

Enjoy :)
#2
One problem. QM exits without waiting for the temporary macro. It waits only for Eval. I tested with QM 2.1.8 (future version), where E behavior is slightly changed. Use this code for Eval function (Eval must be function, not macro):

Code:
Select All      Help
wait 0 H mac(newitem("temp_macro" _command "temp_macro_template" "" "\User\Temp" 1))
#3
aah, yes that is even better, thank you. before I didn't have it clean up the temp macro, but it can cause problems when you have an error
#4
Quote:it can cause problems when you have an error

:?:
#5
nevermind, I think I was confusing that with something else
#6
Now I tested with older QM versions. In QM prior to 2.1.7, mac does not return thread handle, and waiting does not work, although runs without error. Maybe better would be to remove E from bat file.

Code:
Select All      Help
@ECHO OFF
"c:\program files\quick macros 2\qmcl.exe" M "Eval" C %*

and return to RunTextAsMacro

Code:
Select All      Help
RunTextAsMacro _command
;instead of
;wait 0 H mac(newitem("temp_macro" _command "temp_macro_template" "" "\User\Temp" 1))
#7
They could also use something like PsKill to kill QM from the batch file.


Forum Jump:


Users browsing this thread: 1 Guest(s)