I'm trying to create a script that will trigger when a Bullzip Print dialog displays.
Print dialog is known as Bullzip PDF Printer 11.7 - Create File from Window Spy.
The script will test for a specific text string and replace with an alternate string in the file naming field.
If the File Name field (also known as ClassNN: TextBoxU15) contains
"C:\Users\username\Documents\Litigation\temp dump\PDF printouts\public.hcad.org - Print.pdf" ,
it would replace "public.hcad.org - Print.pdf" with "cad.pdf".
I don't have any experience with using IF statements in AHK, so not sure how to set this up.
Any help is appreciated.
Thanks in advance,
weg
Replace Default String - Print Dialog
-
- Posts: 60
- Joined: 11 Feb 2016, 11:49
Replace Default String - Print Dialog
I say this optimistically . . . One day I'll understand it.
But today is not that day!
But today is not that day!
-
- Posts: 60
- Joined: 11 Feb 2016, 11:49
Re: Replace Default String - Print Dialog
Where am I messing up? The procedure seems to simply be replacing the original string with itself back into the dialog Filename field.
Not understanding the StrReplace statement, I suppose.
And how can I have this residing in the background and have it trigger without using the Right mouse button?
Thanks in advance,
weg
Not understanding the StrReplace statement, I suppose.
Code: Select all
#IfWinActive Bullzip PDF Printer 11.7 - Create File
RButton::
ControlGetText, origFilename, TextBoxU15
;MsgBox %origFilename%
defaultName = public.hcad.org - Print.pdf
newName = cad
IfInString, origFilename, %defaultName%
{
StringReplace, OutputVar, origFilename, defaultName , newName
send %OutputVar%
return
}
#IfWinActive
Thanks in advance,
weg
I say this optimistically . . . One day I'll understand it.
But today is not that day!
But today is not that day!
Re: Replace Default String - Print Dialog
It is StringReplace, OutputVar, origFilename, %defaultName%, %newName%
Remember to wrap your variables in %%. You can also use the StrReplace function:
OutputVar:=StrReplace(origFilename, defaultName, newName)
in which case you don't wrap %% around your variable names.
You can use a SetTimer + IfWinActive to check for a Window. Or a shellhook even (google "shellhook new window autohotkey" if you want to know) but a simple WinWaitActive should do it as well like so:
Just so you know: there is a nice function by justme WatchFolder() https://autohotkey.com/boards/viewtopic.php?f=6&t=8384 which can watch a folder that way you could automatically move new files created in the "C:\Users\username\Documents\Litigation\temp dump\PDF printouts\" folder to a new location and at the same time give them a new name.
Remember to wrap your variables in %%. You can also use the StrReplace function:
OutputVar:=StrReplace(origFilename, defaultName, newName)
in which case you don't wrap %% around your variable names.
You can use a SetTimer + IfWinActive to check for a Window. Or a shellhook even (google "shellhook new window autohotkey" if you want to know) but a simple WinWaitActive should do it as well like so:
Code: Select all
origFilename=C:\Users\username\Documents\Litigation\temp dump\PDF printouts\public.hcad.org - Print.pdf
WinTitle=Bullzip PDF Printer 11.7 - Create File
defaultName = public.hcad.org - Print
newName = cad
Start:
WinWaitActive, %WinTitle%
Sleep 100 ; just give it a bit of time
ControlGetText, origFilename, TextBoxU15, %WinTitle%
IfInString, origFilename, %defaultName%
{
StringReplace, OutputVar, origFilename, %defaultName%, %newName%
; ControlSetText [, Control, NewText, WinTitle, WinText, ExcludeTitle, ExcludeText]
; ControlSetText, TextBoxU15, %OutputVar%, %WinTitle%
MsgBox %OutputVar%
}
Sleep 100 ; just give it a bit of time
; Send {enter} ; to save?
; Gosub, Start
Return
-
- Posts: 60
- Joined: 11 Feb 2016, 11:49
Re: Replace Default String - Print Dialog
Thank you for the great input on this and I do see where I messed up on the variable references you mentioned.
Now, although the Msgbox pops up with the new %OutputVar% string to demonstrate the StringReplace result, the string in the Print dialog File name field is not being replaced. Nothing seems to be happening to replace the origFilename in the Print file naming field.
Is there another action that needs to happen to paste(?) or input the replace results into the data field?
Thanks in advance,
weg
Now, although the Msgbox pops up with the new %OutputVar% string to demonstrate the StringReplace result, the string in the Print dialog File name field is not being replaced. Nothing seems to be happening to replace the origFilename in the Print file naming field.
Is there another action that needs to happen to paste(?) or input the replace results into the data field?
Thanks in advance,
weg
I say this optimistically . . . One day I'll understand it.
But today is not that day!
But today is not that day!
Re: Replace Default String - Print Dialog
ControlSetText(this is already commented in the script guest provided), or send it Send % OutputVar, or paste it:
Code: Select all
clipboard := OutputVar
Send ^v
-
- Posts: 60
- Joined: 11 Feb 2016, 11:49
Re: Replace Default String - Print Dialog
So far, with enabling ControlSetText, it works great. Thank you for clarifying swagfag; sorry for not thinking through on why were the commented options listed.
What is the idea of showing Gosub, Start?
Why would I need that?
Thank you,
weg
What is the idea of showing Gosub, Start?
Why would I need that?
Thank you,
weg
I say this optimistically . . . One day I'll understand it.
But today is not that day!
But today is not that day!
Re: Replace Default String - Print Dialog
the gosub will, effectively, restart the script, calling WinWaitActive, which will hang until the window is focused.... create a script that will trigger when a Bullzip Print dialog displays
-
- Posts: 60
- Joined: 11 Feb 2016, 11:49
Re: Replace Default String - Print Dialog
Since I want to visually confirm that the StringReplace has worked properly, the gosub will cause the script to start/run/restart until I press Enter to close the dialog, correct?
Usually, I stack some of my everyday type scripts in a AHKstartup.ahk file using #Include statements to avoid having multiple AHK icons in the Task Tray and they all work just fine. They sit in the background, basically, until activated by a key press or mouse click. Since I have yet to master AHK, I'm not sure what it is about this new script that seems to prevent it from activating when the Print dialog displays if the script is #Include'd in the startup script. I have to Run this new script outside of the startup to get it to work. And it is a one-time use without enabling the gosub.
I did do a bit of reading on the "shellhook new window" to see if that was the direction I need to go to make this script resident(?) and simply watching for the BZ print dialog to become active in order to trigger. However, several of the discussions went deep-dive too quickly for me to follow.
What am I not understanding about #Include'ing this script?
Thank you,
weg
Usually, I stack some of my everyday type scripts in a AHKstartup.ahk file using #Include statements to avoid having multiple AHK icons in the Task Tray and they all work just fine. They sit in the background, basically, until activated by a key press or mouse click. Since I have yet to master AHK, I'm not sure what it is about this new script that seems to prevent it from activating when the Print dialog displays if the script is #Include'd in the startup script. I have to Run this new script outside of the startup to get it to work. And it is a one-time use without enabling the gosub.
I did do a bit of reading on the "shellhook new window" to see if that was the direction I need to go to make this script resident(?) and simply watching for the BZ print dialog to become active in order to trigger. However, several of the discussions went deep-dive too quickly for me to follow.
What am I not understanding about #Include'ing this script?
Thank you,
weg
I say this optimistically . . . One day I'll understand it.
But today is not that day!
But today is not that day!
Re: Replace Default String - Print Dialog
You can run it as a standalone script (it consumes very little memory) - if you want it to be part of your main script you can use SetTimer like so
Code: Select all
; add this at the top of your main script
origFilename=C:\Users\username\Documents\Litigation\temp dump\PDF printouts\public.hcad.org - Print.pdf
WinTitle=Bullzip PDF Printer 11.7 - Create File
defaultName = public.hcad.org - Print
newName = cad
SetTimer, CheckBullZip, 1000 ; check for window each second -
; --------------------------------------------
;;; your main script code here
; --------------------------------------------
; add this at the bottom of your main script
CheckBullZip:
IfWinNotActive, %WinTitle%
Return ; window is not active so return (wait a second and try again)
Sleep 100 ; just give it a bit of time
ControlGetText, origFilename, TextBoxU15, %WinTitle%
IfInString, origFilename, %defaultName%
{
StringReplace, OutputVar, origFilename, %defaultName%, %newName%
; ControlSetText, TextBoxU15, %OutputVar%, %WinTitle%
MsgBox %OutputVar%
}
Sleep 100 ; just give it a bit of time
; Send {enter} ; to save?
Return
; /bottom of your main script
-
- Posts: 60
- Joined: 11 Feb 2016, 11:49
Re: Replace Default String - Print Dialog
Thank you for your input. I'm giving it a try for a time to see how it behaves.
To be clear, the CheckBullZip script procedure will be activated every second, in order to watch for the dialog window, even though a user may go several hours between usage of Bullzip?
Thank you,
weg
To be clear, the CheckBullZip script procedure will be activated every second, in order to watch for the dialog window, even though a user may go several hours between usage of Bullzip?
Thank you,
weg
I say this optimistically . . . One day I'll understand it.
But today is not that day!
But today is not that day!
Re: Replace Default String - Print Dialog
Yes that is correct, it will take minimal resources so there is nothing to worry about I think. The WinWaitActive from the first script just waits for the window to popup and therefore stall any other part of the script as you have noticed. So SetTimer is the easiest solution if you want to have it in your main script.
-
- Posts: 60
- Joined: 11 Feb 2016, 11:49
Re: Replace Default String - Print Dialog
Here's what I did with some back 'n forth testing and seems to work as needed and eliminates the need for the Timer setup. Let me know where I may be not thinking this through correctly. I pulled the variable declarations out of the auto-exec section and located within the body of the #IfWinActive script itself.
The only difference I was hoping to accomplish is not needing to do a Mouse, or such, trigger; simply activates when the Print dialog pops up. Was a bit uncomfortable with a Timer running a script in the background when the script might not be needed for several hours at a time, depending on circumstances of the workflow.
I have this script in its own AHK file called "BullZip NameFile CAD myversion.ahk" and #Include'ing from the startup file like:
Here is the script which is triggered with Ctrl-RButton when the Print dialog appears:
I guess we're done with this.
It isn't so much that I "want it to be" part of my main startup script; that is simply my neophyte way of avoiding numerous tray icons from scripts that have been initiated. I've still got some misunderstandings about the why-nots on this, but seems like we've beat on this one pretty well.
Thank you for all the good help,
weg
The only difference I was hoping to accomplish is not needing to do a Mouse, or such, trigger; simply activates when the Print dialog pops up. Was a bit uncomfortable with a Timer running a script in the background when the script might not be needed for several hours at a time, depending on circumstances of the workflow.
I have this script in its own AHK file called "BullZip NameFile CAD myversion.ahk" and #Include'ing from the startup file like:
Code: Select all
#Include %A_Scriptdir%\~ myNew AHKs\BullZip NameFile CAD myversion.ahk
Code: Select all
#IfWinActive, Bullzip PDF Printer 11.7 - Create File
^RButton::
origFilename=C:\Users\username\Documents\Litigation\temp dump\PDF printouts\public.hcad.org - Print.pdf
WinTitle=Bullzip PDF Printer 11.7 - Create File
defaultName = public.hcad.org - Print
newName = cad
Sleep 100 ; just give it a bit of time
ControlGetText, origFilename, TextBoxU15, %WinTitle%
IfInString, origFilename, %defaultName%
{
StringReplace, OutputVar, origFilename, %defaultName%, %newName%
; ControlSetText [, Control, NewText, WinTitle, WinText, ExcludeTitle, ExcludeText]
ControlSetText, TextBoxU15, %OutputVar%, %WinTitle%
;MsgBox %OutputVar%
}
Sleep 100 ; just give it a bit of time
Send {End} ;Send cursor to end of string so I can see if the StringReplace worked correctly.
; Send {enter} ; to save?
;Gosub, Start
;Return
#IfWinActive
It isn't so much that I "want it to be" part of my main startup script; that is simply my neophyte way of avoiding numerous tray icons from scripts that have been initiated. I've still got some misunderstandings about the why-nots on this, but seems like we've beat on this one pretty well.
Thank you for all the good help,
weg
I say this optimistically . . . One day I'll understand it.
But today is not that day!
But today is not that day!
Who is online
Users browsing this forum: Google [Bot], imstupidpleshelp, JoeWinograd, mikeyww, ositoMalvado, Rohwedder, usser and 179 guests