Page 1 of 1

alternative way to trigger SaveAs dialog

Posted: 02 Apr 2020, 07:44
by JKnight_xbt33
Dear all,
I had made a thread: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=73262
The suggestions helped me make my script more reliable...for a while.

Then one day I noticed the issue re-occuring. I decided to manually trigger SaveAs and to my surprise the script carried on working from there.

Problem: it seems therefore using send ^+{s} to trigger SaveAs is unreliable. Sometimes the SaveAs menu pops up and other times I will have to manually click it to make it work.

I wanted to use ComObject but I am afraid ComObject will trigger the whole process of saving the file in a folder. Which I don't want.

Code: Select all

^#y::
setkeydelay , -1
WinGet,ID,ID,A
InputBox, complaint, Enter complaint
WinActivate,ahk_id %ID%
send ^+{s}  ;shortcut for file-> save as
WinWaitActive, Save As ; 
sleep, 1000
ControlSetText,Edit1, %complaint% initial assessment,A
Is there more reliable way to trigger SaveAs in PDF files?
your help is always appreciated
J

Re: alternative way to trigger SaveAs dialog

Posted: 02 Apr 2020, 09:03
by boiler
Which program’s Save As dialog box are you trying to open?

Instead of:

Code: Select all

Send ^+s
(the { } you had around the s are not required)

...this can be more reliable:

Code: Select all

Send, {Ctrl down}{Shift down}s{Shift up}{Ctrl up}
...or even this:

Code: Select all

Send, {Ctrl down}{Shift down}
Sleep, 50
Send, s
Sleep, 50
Send, {Shift up}{Ctrl up}

Re: alternative way to trigger SaveAs dialog

Posted: 03 Apr 2020, 08:02
by JKnight_xbt33
I am triggering SaveAs on pdf files opened on internet explorer.

I'll try the second script you posted with the 50ms sleep.

After a few weeks of using this I'll be able to know how reliable it is.

Update: I've just tested the suggestion on 5 different PDF files. It worked on 2 out of 5 of the files even if I reload the script.

Conclusion: some sort of matrix glitch, I don't know what to make of it. Perhaps in a few months-year when am more familiar on AHK I'll look back and understand.

Appreciated
J

Re: alternative way to trigger SaveAs dialog

Posted: 03 Apr 2020, 09:24
by boiler
Just have it try again until it works. This should work every time:

Code: Select all

loop {
	Send, ^+s
	Sleep, 500
} until WinActive("Save As ahk_class #32770")

Re: alternative way to trigger SaveAs dialog

Posted: 06 Apr 2020, 07:51
by JKnight_xbt33
Great so I tried the latest script 9 times.

7/9 times no issues.
2/9 times it paused after the 1st input box, but when I simply clicked on PDF the script carried on as normal.

conclusion: This is the most reliable version yet. The issue with needing to click inside the PDF shows the script is sometimes losing focus for the PDF file. This explains why it carried on as normal after i clicked in the PDF, because the loop is continuously firing the SaveAs shortcut.

Improvements I can make:
after the input box I can put a short controlclick for the PDF window which will force the focus. Saves me having to click if it pauses.

Many thanks

Re: alternative way to trigger SaveAs dialog  Topic is solved

Posted: 06 Apr 2020, 08:50
by boiler
Edit: Glad it works, but see I pasted the same line twice without editing the second one. The following is what I meant and would be even more reliable:

Code: Select all

loop {
	WinActivate,ahk_id %ID%
	WinWaitActive,ahk_id %ID%
	Send, ^+s
	Sleep, 500
} until WinActive("Save As ahk_class #32770")

Re: alternative way to trigger SaveAs dialog

Posted: 07 Apr 2020, 04:12
by JKnight_xbt33
Perfect, no issues seen with this script.

:D

Re: alternative way to trigger SaveAs dialog

Posted: 07 Apr 2020, 05:30
by boiler
Noticed a mistake. See how I edited it in that post. Meant for the second line to be WinWaitActive, not another WinActivate.

Re: alternative way to trigger SaveAs dialog

Posted: 07 Apr 2020, 06:00
by teadrinker
@boiler
WinActivate wrote:Six attempts will be made to activate the target window over the course of 60ms. Thus, it is usually unnecessary to follow WinActivate with WinWaitActive or IfWinNotActive.

Re: alternative way to trigger SaveAs dialog

Posted: 07 Apr 2020, 06:04
by boiler
teadrinker wrote:
07 Apr 2020, 06:00
@boiler
WinActivate wrote:Six attempts will be made to activate the target window over the course of 60ms. Thus, it is usually unnecessary to follow WinActivate with WinWaitActive or IfWinNotActive.
Good to know. Thanks.