12

I need to click a button called "save" in a Adobe Air application called Arthropod. I can launch the app in the bat file with this:

cd C:\Program Files\Arthropod
start /w Arthropod.exe

Once it pops up there is a save button on the UI. How can I click it with the bat file?

I was reading this:

http://www.ehow.com/how_7788761_press-buttons-batch-file.html

which showed how to simulate clicks to the file menu and other tabs in MS Word but how does one do this on any other button?

P.S. the text on the button is "Save" that's the only unique identifier I can think of for that button. Is there anything is batch where I can say something like (pseudo code):

$('button[text="Save"]').click();
Laf
  • 7,965
  • 4
  • 37
  • 52

4 Answers4

18

There is no native way to do this cleanly.

But you can use VBS to simulate keystrokes if you want, something similar to AutoIT, but nowhere as flexible. On the Plus side of things, you don't need to download VBS. It's been included in every version of Windows since 95.


I am including an example that launches notepad.exe, then types the following into it:

Hello World!
abcDEF

.
The following single line is called LaunchNotepad.bat :

cscript /nologo LaunchNotepad.vbs

.
The following is the contents of LaunchNotepad.vbs :

' Create WScript Shell Object to access filesystem.
Set WshShell = WScript.CreateObject("WScript.Shell")

' Start / Run NOTEPAD.EXE
WshShell.Run "%windir%\notepad.exe"

' Select, or bring Focus to a window named `NOTEPAD`
WshShell.AppActivate "Notepad"

' Wait for 5 seconds
WScript.Sleep 5000

WshShell.SendKeys "Hello World!"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "abc"
WshShell.SendKeys "{CAPSLOCK}"
WshShell.SendKeys "def"

Note that if there is one or more instances of Notepad.exe already open, and it takes more than 5 seconds to open notepad, the above code may select the the last active instance of notepad and type into that.


To get the VBS code to work how you want, you'll need to learn how to navigate around Adobe Air by keyboard. Usually either tabs and/or arrow-keys will suffice. Sometimes you may need to use the ALT key to move into the menus.

Also, you might actually be able to use a series of keyboard commands like ALT+FSENTER, or even a keyboard shortcut like CTRL+S.

To send TAB, ALT+F, and CTRL+S :

WshShell.SendKeys "{TAB}"        ' TAB                TAB Key
WshShell.SendKeys "%F"           ' ALT-F              (F)ile Menu
WshShell.SendKeys "^S"           ' CTRL-S             Save File
WshShell.SendKeys "%(Fa){ENTER}" ' ALT-F+ALT-A ENTER  (F)ile -> Save (A)s -> (ENTER)
WshShell.SendKeys "{UP}"         ' Up Arrow           Up Arrow
WshShell.SendKeys "{DOWN}"       ' Down Arrow         Down Arrow
WshShell.SendKeys "{LEFT}"       ' Left Arrow         Left Arrow
WshShell.SendKeys "{RIGHT}"      ' Right Arrow        Right Arrow
James K
  • 4,005
  • 4
  • 20
  • 28
6

You can use AutoIt to do this. You can generate a script that would click on the "Save" button, and call the generated EXE file from a batch file.

Laf
  • 7,965
  • 4
  • 37
  • 52
  • thanks. I used Autoit and I just needed 3 lines of code. Awesome tool! –  Oct 25 '12 at 19:54
  • @WackGet I suggest you record a macro with AutoIt and see those lines for yourself. That way there's more chances the code generated will fit your needs. – Laf Oct 02 '17 at 13:49
  • @WackGet don't remember that was so many years ago, but I just followed a youtube tutorial. It's a pretty simple tool to use. –  Oct 02 '17 at 14:14
2

Winbatch is another program that can send keystrokes, but unlike AutoIt I don't believe it's free.

0

You cannot automate button clicks with a bat file. If it were possible, you would still need some kind of API for Adobe Air for access the control itself. But if there is a keyboard shortcut to this button, you can simulate a keystroke and send that to the application.

ORION
  • 2,374
  • 2
  • 22
  • 31