Running ad-hoc scripts from the command line
#1
Guests
Posted 04 November 2006 - 07:13 AM
autohotkey.exe -script 'winactive, Total Commander'
so that the user doesn't have to create files for trivial scripts.
Of course, there should be a way to combine multiple commands. Something like
autohotkey.exe -script 'ifwinnotexist, MyWin { Run, MyApp} else winactivate'
#2
Posted 04 November 2006 - 09:23 AM
And the combined syntax isn't even possible currently...
#3
Guests
Posted 04 November 2006 - 03:06 PM
The syntax was only an example. AH shouldn't rely on all commands being on separate lines. This limitation is very old-fashioned. None of the modern scripting languages I used had this kind of problem. Not even Python where the indenting level has special syntactical meaning,
#4
majkinetor !
Posted 04 November 2006 - 03:23 PM
#5
Guests
Posted 04 November 2006 - 05:51 PM
#6
Guests
Posted 04 November 2006 - 06:09 PM
#7
Posted 04 November 2006 - 06:35 PM
Allowing a command separator isn't in the spirit of AHK, where lot of commands end by a naked string, so it is hard to tell if some symbol is part of the string or a command separator.
Now, you can write a script that takes a parameter which is a scriptlet. It can even split the parameter along an arbitrary chosen separator, getting lines to process with the script able to dynamically interpret AHK commands.
So you can do:
autohotkey.exe ScriptExec.ahk "WinActive Some Editor"
#8
Posted 04 November 2006 - 06:46 PM
you can write a script that takes a parameter which is a scriptlet. It can even split the parameter along an arbitrary chosen separator, getting lines to process with the script able to dynamically interpret AHK commands.
So you can do:
autohotkey.exe ScriptExec.ahk "WinActive Some Editor"
Nice idea PhiLh
I would prefer to compile and have it as ScriptExec.exe
#9
Guests
Posted 04 November 2006 - 08:38 PM
Thanks.
#10
another guest
Posted 05 November 2006 - 01:03 AM
#NoTrayIcon FileAppend,%1%,temp.ahk FileSetAttrib,+H,temp.ahk RunWait,AutoHotkey.exe temp.ahk FileDelete,temp.ahk
It'll work as both a script or compiled, but obviously it'll need AHK installed in either case. To have it standalone, you'd probably have to manually code in every pertinent command and parse the input against all of them... :shock:
As for multiple commands on one line, you use either use `n in one parameter, or use multiple parameters and join them in the script:
#NoTrayIcon Loop,%0% FileAppend,% "`n" . %A_Index%,temp.ahk FileSetAttrib,+H,temp.ahk RunWait,AutoHotkey.exe temp.ahk FileDelete,temp.ahk
E.g. AutoHotkey.exe ahkexec.ahk "WinActivate,Calculator" "MsgBox,Script Completed."
#11
Posted 05 November 2006 - 01:30 AM
#NoTrayIcon #SingleInstance ignore StringReplace, code, 1, ``n, `n, All If !code ExitApp file = %A_Temp%\cmd%A_Now%.ahk FileAppend, %code%, %file% Run, %A_AhkPath% "%file%", %A_WorkingDir%, , pid Sleep, 1000 FileDelete, %file% FileAppend, %pid%, * ExitAppe.g. Run: cmd.ahk "var = 100`nmsgbox var = %var%"
#12
Guests
Posted 05 November 2006 - 06:12 AM
#13
Veovis not logged in
Posted 05 November 2006 - 06:36 AM
I am confused by a couple things in your code titan,
StringReplace, code, 1, ``n, `n, All
what is ``n for? At first i thought it was a work around for being able to have something like "msgbox, test`ntest" (a msgbox with multiple lines) encoded, but it doesnt work...
FileAppend, %pid%, *
In the ahk documentation it says that this will send it to stdout, but that it wont appear in the console. So why do you have that line?
But seriously, this is soooooooooooooooooooooooooooo cool! Mwhahahaha you should have seen me
cmd.ahk "msgbox, test"
cmd.ahk "msgbox, SWEET!"
cmd.ahk "msgbox, hmmm this is getting fun... MWAHAHAH Dancing window time!"
cmd.ahk "wingetpos,x,y,,,A`nloop,20`n{`nwinmove,A,,x+5,y`nwinmove,A,,x,y+5`nwinmove,A,,x-5,y`nwinmove,A,,x,y-5`n}"This is so cool! Do you know how many times i have needed to move some window (like an anoying pop up thing that wont go away) and winmove could do it in a heart beat, but i have to make a new file, type the thing, save and run. mwahahah this is sooo cool!
p.s. try the dancing window thing! its cool!
#14
Posted 05 November 2006 - 04:11 PM
Thanks.
#15
Posted 06 November 2006 - 09:44 AM
First, AHK itself is used to create another AHK script and to execute it. Much better (faster) solution is to create AHK script in batch and then execute it.




