- Launch the application
- Enter my password into the text box, and click OK.
- Select File > SaveAs... in the main application
- Enter the new file name in the Save As dialogue, and click Save
- Exit the application
from pywinauto.application import Application
def backup_ace_money(pwd,file_name):
# Launch the application
app = Application().start(r'C:\Program Files (x86)\AceMoney\AceMoney.exe', timeout=10)
# Enter password, click OK
pwd_dlg = app.window(title='Enter password')
pwd_dlg.Edit.type_keys(pwd)
pwd_dlg.OKButton.click()
# Select File > SaveAs in main window
main_dlg = app.top_window()
main_dlg.menu_select('File -> Save As...')
# Enter the file name in the Save menu, and click Save
save_dlg = app.window(title='Save As')
save_dlg.SaveAsComboBox1.type_keys(file_name)
save_dlg.SaveButton.click()
# Exit AceMoney
main_dlg.close()
The only (hah!) difficult bit was discovering the name of the box to type the file name into. (I confess that discovering the mere existence of the menu_select() function took me more time, and extreme muttering, than it should have.) The print_control_identifiers() function was indispensable for finding the name of the relevant control, but the great advantage is you can access by (relatively robust) name, not (incredibly fragile) screen position.
So, a couple of hours and 10 lines of code later, this task has now been automated.
And now I'm thinking about what to automate next.