I'm simply making a script to automatically update my GitHub repo through the command prompt in Windows.
The first line of code after the command prompt is open won't send, unfortunately. I believe it is because the string includes commas, but I can't find the right syntax for making "pushd D:\Media Lists\Website, Blog, and Wordpress_thefloodplains\thefloodshark.Github.io" send as a string before inputting {Enter} like in the below code:
run cmd.exe
WinWait, ahk_exe cmd.exe ;
ControlSend, , pushd D:\Media Lists\Website, Blog, and Wordpress\_thefloodplains\thefloodshark.Github.io{Enter}, ahk_exe cmd.exe
sleep, 2000
ControlSend, , git add .{Enter}, ahk_exe cmd.exe
sleep, 2000
ControlSend, , git commit -m auto{Enter}, ahk_exe cmd.exe
sleep, 2000
ControlSend, , git push{Enter}, ahk_exe cmd.exe
sleep, 3000
Exit
As it stands, the script runs, but it won't input that first line with my GitHub repo location. The rest of the ControlSend inputs work, though.
Any and all ideas would be deeply appreciated.
CodePudding user response:
The problem is indeed about your path having commas and you not escaping them (`,
).
You can read about escaping in AHK here.
But really, this is just a problem when specifying legacy strings.
Instead, what I'd say you really want to do is to just use the expression syntax and specify the string explicitly, like so:
ControlSend, , % "pushd D:\Media Lists\Website, Blog, and Wordpress\_thefloodplains\thefloodshark.Github.io{Enter}", % "ahk_exe cmd.exe"
sleep, 2000
ControlSend, , % "git add .{Enter}", % "ahk_exe cmd.exe"
sleep, 2000
ControlSend, , % "git commit -m auto{Enter}", % "ahk_exe cmd.exe"
sleep, 2000
ControlSend, , % "git push{Enter}", % "ahk_exe cmd.exe"
sleep, 3000
And now on a more unrelated note, this implementation is really bad/low tech.
Really you'd just want to create an actual script for your command line and run that script. Since you seem to be using cmd, you could create a simple batch script like:
pushd D:\Media Lists\Website, Blog, and Wordpress\_thefloodplains\thefloodshark.Github.io
git add .
git commit -m auto
git push
And then run it with AHK by using e.g. Run
(docs):
Run, % "C:\Users\User\Desktop\my cool scripts\script.bat", % "C:\Users\User\Desktop\my cool project folder"