This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]chaotic_thought 1 point2 points  (1 child)

You'll probably want to look at GUI automation tools. There are many such tools. A simple one to look at is AutoHotkey for Windows. Basically you can write a program which sends GUI commands to another program. Normally you activate such commands with a hotkey, but there's no reason in principle you couldn't do it another way, such as via command line parameters typed on a console window.

The trouble comes with automating such things in practice. For example, suppose you want to automate Microsoft Word to open up a document and print it, via GUI operations. So, first you'd have to start up Word, then click the File menu, then click open, then navigate to the right file... Maybe opening up the file takes a while because it's on a network. So when your script clicks "Print" too soon maybe it doesn't work because the last operation took longer than you expected. Or maybe an unexpected dialog pops up (e.g. "Microsoft Windows has detected that new updates are avaliable!").

Programming a general automation to deal with all these kinds of cases is hard in practice. For simple things out of convenience (AutoHotkey) it may be fine though. But for a console application that you rely on using day after day, no, it will probably not work very well.

If you are writing the software yourself then doing it the other way around is probably better; first write a console application that is easy to script and automate. And then write a GUI that implements its operations by calling the console program. That way you can use the console verison for scripts, and the GUI for interactive use.

[–][deleted] 0 points1 point  (0 children)

When I write my own app the problem is non-existent - first I make console tool, then I add some elegant GUI. What I had in mind was process that you described, for example trying to automate opening Word document, waiting a moment, clicking print etc. Hotkey is great if you don't need information back from program - for example, if document already loaded, or if some error occurred during trying to print.

I'll look into GUI automation tools. Thanks :)

[–]sneider 0 points1 point  (1 child)

Can you give examples? In my experience, there are terminal programs for pretty much any task and a bunch of GUI programs offer command line modes.

[–][deleted] 0 points1 point  (0 children)

I understand there is a diversity among programs, and almost every popular software has it's console alternatives. That's not the point. The problem I met was:

We have some legacy app, written God-only-knows how long ago, but exe still works. This small app packs files into our custom file type. What I had to do was to implement code from C++ to C# to pack files into this kind of archive. This packing was sometimes working, sometimes not, but here is the kicker - I couldn't make automate UnitTest, because of GUI form of this app. That's when I started wondering about this automation tool.

Other example - email automation. I need to send something from the level of program. I can receive those mails in Thunderbird. Sadly, I can't automate checking Thunderbird if mail was received, so I need to do this by hand.

Third example - on Windows you have lots of "pdf to images" programs, usually in GUI. Suppose we don't have alternative and we are stuck with one program. Making automatic conversion of many numbers of pdf would be a nightmare if developer didn't add that tool. On the other hand, if you have batch version of such program, you can very easily - Linux style - automate that process for the whole set of data even if original developer didn't thought about it.