AutoHotKey How to save file as XPS without dialog box - autohotkey

At work I have to take "screen shot" of a 3rd party vendor website 300-400 times a day, and save it as a XPS or PDF file. I already build a program that will send keys to do Ctr+P, Select, Enter, Write File Name, Enter. But I am wondering if there are faster way?
What I have in mind is to execute this command automatically without the need of a Print dialog box, and physically enter the file name, and press enter to save the XPS files.
I am using Window 7 with Internet Explorer.
Send, {CTRLDOWN}p{CTRLUP}
Sleep, 1500
Send, {ENTER}
Sleep, 500
Send, {ENTER}
Sleep, 500
PutWindowInFocus("Save")
if (active) {
Send, %cin% %dateOfService% Eligibility
Sleep, 1000
} else {
Send, %cin% %dateOfService% Eligibility
Sleep, 1000
}
Send, {ENTER}
Sleep, 2000

Combine Purrint's Print to default printer option when hitting printscreen with PDF Creator's automatic-saving feature and you have it reduced to a single keypress. If the screen shots are done on a schedule, you can even configure Purrint to take the screenshot every X seconds, reducing it to zero keystrokes.

Related

how to timeout a script when it runs into an event it can't handle autohotkey

I have a script that opens a browser and saves a webpage and I want it to cancel the job on a time out. If it's waiting for a window that doesn't show up to stop running and start over. How would I go about this? Here's my short script:
Run, www.google.com
WinWaitActive ahk_exe firefox.exe
Sleep, 1000
Send ^s
WinWait, Save As
Send ^{Backspace}
Sleep, 1000
SendRaw www.google.com.html
Sleep, 500
ControlClick, Button2, Save As,, Left, 1, NA
We can use the Timeout parameter of WinWaitActive:
From the docs:
WinWaitActive / WinWaitNotActive
Waits until the specified window is active or not active.
WinWaitActive , WinTitle, WinText, Timeout, ExcludeTitle, ExcludeText
If it takes longer than the value in the Timeout parameter, then the script continues and the variable ErrorLevel is set to 1/True.
By putting this entire script under a Label (here called savePageSubroutine), we can go back to this point with a goto statement.
savePageSubroutine:
Run, www.google.com
WinWaitActive ahk_exe firefox.exe,,1000 ; Tune this value to taste
if (ErrorLevel)
goto savePageSubroutine
Sleep, 1000
Send ^s
WinWait, Save As
Send ^{Backspace}
Sleep, 1000
SendRaw www.google.com.html
Sleep, 500
ControlClick, Button2, Save As,, Left, 1, NA
return

Lost focus in browser when using clipboard for search query [autohotkey]

I am using a simple script to run a google/wikipedia/etc search using a hotkey, unfortunately after the search result appears in a new tab, I have to click because the tab is not on focus, although the browser windows is on focus. I tried to add a WinActivate but it's not working. This script used to work as expected before a new OS installation. Why is this script making lose focus on the browser?
Here's the script
^+g::
{
Send, ^c
sleep 200
Run, https://www.google.com/search?hl=en&q=%Clipboard%
sleep 50
WinActivate, ahk_exe waterfox.exe
}
Return
I don't know why, but it looks like increasing the delay between the Run and the WinActivate seems to fix it.
^+g::
{
Send, ^c
sleep 200
Run, https://www.google.com/search?hl=en&q=%Clipboard%
sleep 500 ;Up from 50, you might be able to fine-tune this number based on your computer's speed
WinActivate, ahk_exe waterfox.exe
}

Making AHK script in Notepad ++

Im trying to make an ahk script to try and simplify a one time use script. Pretty much im running over 1000 commands in a game one after one another .Currently I have something like this. I have all the commands in a single text file just not with any ahk coding.
.waypointadd 1 100234 40 -469
.waypointadd 2 99549 34 5
.waypointadd 3 100615 37 -160
.waypointadd 4 100817 27 -457
.waypointadd 5 100503.5 10.5 -647.5
.waypointadd 6 100494.5 10.5 -625.5
This goes on for a while. Im new to using expressions and such and am pretty much trying to make it to press enter, type the command, then press enter, then go to the next one. I obviously cant do this manually. I have tried using some basic replace expressions and stuff but not really sure how to do this.
In the end i would want it to look like this
send {enter}
send (command 1)
send {enter}
send {enter}
send (command 2)
send {enter}
you could bind it to a key like....
1::
loop, 1 {
send {enter}
send (command 1)
send {enter}
send {enter}
send (command 2)
send {enter}
}
or make a function when you a press a key. lmk if this helps or not
doSomething() {
send {enter}
send (command 1)
send {enter}
send {enter}
send (command 2)
send {enter}
}
1::
doSomething()
You could store all the commands in your clipboard (CTRL+C them) and then loop through all of them:
Loop, Parse, Commands, `n, `r ;split by linefeed, ignore carriage return
{
SendInput, % A_LoopField "{Enter 2}"
Sleep, 1000 ;however long you need
}
Loads of ways to get the commands into your script, I just went with loading them from your clipboard, should be pretty easy convenient to just copy the block of commands you want and then starting the script.
Then there's a parsing loop.
And then SendInput is used to send the current command follow by two presses of Enter.
Alternatively, if your game supports pasting from clipboard, it would be nice to just load your clipboard with whatever you want to send, and then sending a CTRL+V.
If the code with SendInput is going too fast, you can try switching over to normal Send and maybe even using SetKeyDelay to add even more delay between the keypresses.

AutoHotKey: How to Count number of files in active folder and copy to clipboard?

I have a long list folders that i need to automatically spreadsheet the following two pieces of information into our existing excel document:
Folder Name
File count within that folder
I've written the script up to the point where i now need AHK to get the file count of the active explorer window, copy to clipboard and ALT+TAB/Paste it into the spreadsheet. I plan to loop this script using 'goto' and just monitoring it until it reaches the last folder and use ESC to end the script by eye.
Whats the easiest way to get the numerical value file count of the active window and have it copied to clipboard?
My code so far which is basically using F2 to 'rename' thus copy folder name, alt+tab to spreadsheet, paste it in, move to the file count cell on the spreadsheet, alt+tab back to active explorer window, step into said folder -- and now i'm stuck (where i need to get file count onto clipboard). It's worth noting that i would want the file count to ignore system files like .DS_Store if they're present.
`::
{
Send, {F2}
Sleep, 200
Send, {Ctrl Down}
Sleep, 50
Send, c
sleep, 50
Send, {Ctrl Up}
Sleep, 100
Send, {Alt Down}
Sleep, 50
Send, {Tab}
Sleep, 50
Send, {Alt Up}
Sleep, 100
Send, {Ctrl Down}
Sleep, 50
Send, v
sleep, 50
Send, {Ctrl Up}
Sleep, 100
Send, {Right}
Sleep, 50
Send, {Right}
Sleep, 50
Send, {Right}
Sleep, 100
Send, {Alt Down}
Sleep, 50
Send, {Tab}
Sleep, 50
Send, {Alt Up}
Sleep, 100
Send, {Enter}
^^^^^^^^^^^^^ Need my file count / copy to clipboard here
Esc::ExitApp
}
Maybe have a look at something like this (and follow along in the comments):
; Calculate the number of files in a folder and its subfolders:
SetBatchLines, -1 ; Make the operation run at maximum speed.
FileNum = 0
; FileSelectFolder, WhichFolder ; Ask the user to pick a folder.
WhichFolder := Clipboard ; assumes full path to folder is in clipboard
Loop, Files, %WhichFolder%\*.*, R
{
if A_LoopFileAttrib contains H,R,S ; Skip Hidden, Read-only, or System files
continue ; Skip this file and move on to the next one
FileNum += 1
}
Clipboard := FileNum
ClipWait ; Wait for the clipboard to contain text.
MsgBox %WhichFolder% has %FileNum% files in it (incl. subfolders).
Then, have a look at the following which explains how to read and loop through directories and files:
https://autohotkey.com/docs/commands/LoopFile.htm.
Hth, let us know how you make out . . .

Send, SendInput, SendEvent functions entering single key multiple times

I have created a script in AutoHotKey.I have to Enter the entire file path to be opened in the
file browser.i have used send function but it passes the same keys multiple times. I tried using the function SetKeyDelay but still it enters the keys multiple times. I tried other alternatives as sendInput and SendEvent but still it didnt work.
Even if i terminate the script in between and if the control switches to some Input box or Editor, it starts entering the values into that area. Send function keeps on entering the keys even after the script execution is terminated.
Script:
;Open Adobe Acrobat 8.
run Acrobat.exe sleep, 1000
WinWait, Adobe Acrobat Professional,
Sleep, 1000
;Open Compare Documents Window
send, {ALT}A
Sleep, 1000
send, U
WinWait, Compare Documents,
;Enter File Path
IfWinNotActive, Compare Documents,
WinActivate, Compare Documents,
WinWaitActive, Compare Documents,
Sleep, 1000
send, !H
WinWaitActive, Open,,1000
sleep, 1000
SendEvent, "D:\Sample\a.pdf"
It Enters text something like this
CCCC:::::\\DDDDiiiiii
Things to try:
Update AutoHotkey to the latest version.
Don't use SendEvent. It allows other input to interrupt the text as it is being entered. Use SendInput instead. It is recommended to put the following at the top of all your scripts:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SendMode Input changes Send to use SendInput instead of SendEvent. It buffers the input and sends it all at once instead of letting other keyboard/scripts interrupt the text. See: Send for more information.
Restart your computer and make sure that there are no other AutoHotkey programs running, or that there isn't multiple instances of your Autohotkey script running. This is especially a problem when testing, as you might have launched the same script multiple times, and if the thread hasn't been properly terminated, you may have multiple instances there waiting for the Open window to be activated. Once the Open window has been activated, then you may have 4+ dormant scripts all trying to type at the same time, which would give you the output that you are describing.