ai-feature-image

Use Artificial Intelligence (AI) To Write Programs

I know that most of the people reading this are not computer programmers. What if I told you that by using Artificial Intelligence (AI) you can use a computer programming language you know nothing about to do amazing things in Windows? Even if you DO know something about this programming language, it will be amazingly faster to use AI to write the program. This article will show you how to use AI to write a program that automates fixing problems that sometimes happen in Microsoft Outlook. However, AI can be used to do an almost limitless number of automation tasks in Windows.

In a previous article, “ChatGPT: Give AI (Artificial Intelligence) A Try“, I had AI create a short batch file that would start a program that uses a Windows Service that I don’t want running when the program is NOT running. Maybe some people would find that useful, but most would not. What I learned by doing it was that I needed to know very little about the batch programming language. All I needed to do was describe what I wanted the program to do as if I was telling a professional computer programmer what I wanted the program to do.

Put AI To The Test

Let’s put AI to the test by asking it to write a relatively complex program to repair a Microsoft Outlook “.pst” data file. Please refer to my previous article, “How To Repair An Outlook Data File“, if you have any questions about the repair process. In particular, you will need to know the location of your “Outlook.pst” data file and the location of your “Scanpst.exe” repair program. Every version of Microsoft Outlook comes with the “Scanpst.exe” file.

Programming languages are very much like spoken languages in that some are relatively easy to learn after using them and some of them are not, even after using them a lot. AutoHotKey (AHK), a powerful Windows automation tool, is one of those that is not easy. Even though I’ve written 42 AHK programs (some of those are rewrites) over many years, I generally have to get help from the documentation to write another program. That is one reason why I chose the AHK programming language for this AI challenge. Also, AHK can be extremely helpful in automating computer tasks that you frequently do.

AHK is like batch file programming on steroids. It is a free, open-source, and extremely powerful programming language for Windows that can create Windows programs that do just about anything you want to automate in Windows. If AI can write a somewhat complex AHK program, it should be able to write programs in most computer programming languages. AHK can interpret text file scripts (ending in the “.ahk” extension) line-by-line as it executes. It also can compile a “.ahk” script into a “.exe” executable program that can be run anywhere, even by people who do not have or have never heard of AHK.

Talk To AI

The goal is to have AI write an AHK program that automates the repair of a Microsoft Outlook data file. Here is what I told AI to do:

Write an Autohotkey program to:
1. Run scanpst.exe located at “C:\Program Files (x86)\MicrosoftOffice\root\Office16”
2. Wait for Microsoft Outlook Inbox Repair Tool to open
3. Enter the location “C:\Users\Stu\AppData\Local\Microsoft\Outlook\Outlook.pst” into the “Enter the name of the file you want to scan” box in the “Microsoft Outlook Inbox Repair Tool” window
4. Click on the “Start” button at the bottom of the window

Amazingly, it wrote a good-looking AHK script for doing what I asked, but it DIDN’T WORK. The problem was that it did not do step number 4 above – click on the Start button.

I then asked AI:
The program you wrote did not click on the Start button. Why?

AI responded with an apology:
I apologize for the mistake in my previous response. The ControlClick command may not have worked in some cases due to the timing of the script execution.

To ensure the script clicks on the “Start” button in the “Microsoft Outlook Inbox Repair Tool” window, you can use the ControlSend command instead of ControlClick. Here’s the modified script:

Run, C:\Program Files (x86)\Microsoft Office\root\Office16\scanpst.exe
WinWait, Microsoft Outlook Inbox Repair Tool
WinActivate
ControlSetText, Edit1, C:\Users\Stu\AppData\Local\Microsoft\Outlook\Outlook.pst, Microsoft Outlook Inbox Repair Tool
ControlFocus, Button1, Microsoft Outlook Inbox Repair Tool
ControlSend, Button1, {Enter}, Microsoft Outlook Inbox Repair Tool

The above script worked perfectly. The AHK script I had written to do the same thing was quite different than the script above. That’s because in AHK there are often lots of different ways to do the same thing. The amazing thing for me was that it took me at least two hours to write my own AHK script. It took me less than 10 minutes to write what I wanted AI to do and have it generate the AHK script for me.

Should you want to try this yourself, you would need to:
1. Know how to access an AI program (see “ChatGPT: Give AI (Artificial Intelligence) A Try“)
2. Install AutoHotKey
3. Know the location of the “scanpst.exe” file on your PC
4. Know the location of the “.pst” file on your PC
5. Copy the AHK script the AI generates and paste it into a “.txt” file
6. Change the extension from “.txt” to “.ahk” and then double-click on this file

Your feedback on this article is welcome. Please use the Comments section below to respond.

2 thoughts on “Use Artificial Intelligence (AI) To Write Programs”

  1. I tried it a few weeks ago Stuart – a simple task. Move the mouse to a point on the screen. Click the mouse and then type text at the mouse location. I wanted it to enter a password into a dialogue box.
    I gave up after 15 revisions from the Ai – none of which worked.
    So unless you know something about programming (I don’t beyond simple BASIC) and can advise the Ai how to solve even the minor the problems it will run into I don’t have much confidence at this stage.
    HAL 9000 couldn’t open the outer bay doors for me either.

    1. Hi Reg,
      Thanks for responding.
      As you found, I also found that you have to give AI the “right” requirements. It is no different than asking someone to do a chore but they didn’t quite understand enough to do it the way you wanted.
      I just tried asking this: “Use AutoHotKey to enter 123456 at the center of the screen.”
      It didn’t work so I asked this: “That worked by moving the cursor to the center of the screen but the 123456 was not printed”
      AI responded “I apologize for the confusion. The issue with the previous script is that it moves the mouse cursor to the center of the screen, but it does not click on any text field or window to receive the keystrokes.
      Here is an updated script that will type “123456” at the center of the screen.”
      That one seemed to work.
      The bottom line is that I believe it can be done if the right information is given to AI. In your case, you would need to say something like the password field is (for example) 75% of the way horizontally across the screen and 22% of the way vertically down the screen. The point is that you’re learning what AI needs rather than having to learn the language it is using to write the program.
      Stu

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

WHY NOT SUBSCRIBE TO OUR NEWSLETTER?

Get great content like this delivered to your inbox!

It's free, convenient, and delivered right to your inbox! We do not spam and we will not share your address. Period!