Send our filename
When the Save As dialog appears, the filename box has the keyboard focus, so all we need to do is send our filename, and it will be filled in the right place. If we needed to move keyboard focus a good tip is to use Press Tab to move from object to object.
What we should do is set a variable at the top of the script with our filename, so that we can modify that easily:
Let>filename=%USERDOCUMENTS_DIR%\sample.txt
Assuming we have done this we could just now send the filename and press enter to save it as follows:
Send>filename
Press Enter
However, what if this file already exists? We would get an error and we would have to script the error window and make changes as necessary.
It would be easier to avoid this and check the existence of the file first. Macro Scheduler has a command called IfFileExists. But what do we do if it does exist? We could just delete it? This is fine in this instance because I know that this file is just an example and I'm never going to confuse it with a valid alternative file. But if we wanted to play safe we could give it a new filename. We could use the date and time, and/or a random number on the filename and keep performing the existence check before saving the file.
To keep things simple at this stage we'll just delete the file if it already exists. IfFileExists is given the filename and proceeds onto the next line if it exists. If it doesn't exist it jumps to the associated Endif line. So we should do this:
IfFileExists>filename
DeleteFile>filename
Endif
SetFocus>Save As
Send>filename
Press Enter
The last two lines here are the two that send the filename and press enter to save it. We've added a SetFocus line just for good measure. It shouldn't be needed as the Save As dialog should already be active, but for the sake of example it has been added. There is never any harm in ensuring the correct window has the focus before we send any keystrokes.