I have a Macro to run a multi-page document Scan in Image Capture. It names the new Scan with an incremental number. I would like to show the finished multi-page Scan in the Finder once the Scan is done.
The problem is finding a Condition that will Pause the Macro until all the pages are scanned if Image Capture is no longer the Foreground App.
If Image Capture is the Foreground App it is easy - I just tell the Macro to Pause until a Button with the name "Hide Details" is enabled. (This button only becomes enabled in Image Capture again once all the pages are scanned.)
But most often, if I am scanning lots of pages, Image Capture won't be the foreground App (I will have been getting on with stuff in other Apps while the scan is going on).
And in that case the Button Condition doesn't work. And from searching the Forum, I don't think Keyboard Maestro can detect the condition of buttons that are not in the foreground App?
Another complication is that Image Capture creates the PDF as soon as the first page is scanned and then keeps adding the extra pages to that same file. So, watching my Scan Folder for complete or incomplete files doesn't work, nor does pausing until a specific files exists as that opens the Scans Folder as soon as the first page is scanned.
Anyone have any ideas or tried something similar? Any help much appreciated.
If it makes things clearer (probably not as my Macro is specific to my workflow and numbering of the scans) here is the latest version of it, which does work but reveals the PDF as soon as the first page is scanned rather than waiting for all pages to be scanned).
If Image Capture is adding extra pages to the file on a recurring basis, why not just monitor the size of the file, and if the size remains constant for more than, say, 60 seconds, then treat that as a trigger. I use approaches like this for monitoring things all the time.
(In fact, I think I wrote a macro that takes another macro as a parameter and runs it intermittently until it sees a change in result, at which point I get notified. This helps me do things like monitor devices that are attached to my system. This way the whole "monitoring thing" is isolated in a separate routine, and all I need to do is write a separate macro that takes the measurement.)
In Image Capture you can give a multipage scan (from the Document Feeder) a name but it doesn't increment that name with a number. That's why I've been trying to do the naming and numbering of the scanned multi-page document with Keyboard Maestro.
So, my Macro does this:
Presses the button "Scan" in Image Capture to start the scanning process.
Image Capture scans the first page and creates a file called "Scan" in a set folder.
As it adds more of the pages, it resaves this "Scan" file with the new pages added.
At the end of the scanning process, a button in Image Capture called "Hide Details" becomes enabled. My Keyboard Maestro Macro waits for that to happen and then renames the scanned file with an incremental number - scan-0001, scan-0002 etc.
This works but Image Capture has to be the frontmost App for Keyboard Maestro to see that the button "Hide Details" is enabled which means that if I am scanning lots of pages and start to work on something else, Keyboard Maestro never gets to see the button (until I bring Image Capture to the front again - which is my current workaround).
And if I get Keyboard Maestro to rename the file before all the pages are scanned, Image Capture will make a new file of its own to save the rest of the pages too.
I haven't uploaded the Macro because all the file paths etc are specific to my setup and I've got a Scanner with a Document Feeder which is unusual I think, but I have marked the Action in the Macro that I'm needing help with. The Pause Until part.
I can't find a condition that I can put in this Action that will still work even if Image Capture is not at the front.
This sounds like a good idea but from trying out lots of things this morning I realise that is outside my current ability to know how to achieve I couldn't find any pause until which included monitoring file size. I'm probably just looking at the wrong Actions.
To quickly recap - the below Macro works fine but I'd like to replace the Action with the red dotted lines around, with a pause that will work even if Image Capture is not at the front.
The idea that you are trying to implement doesn't use a PAUSE UNTIL. Instead, it uses a loop that compares the current measurement (which is file size) to the last measurement. You will need a variable to track the last measurement, and a variable to track the time of the last change in measurement (file size increase.) I do this approach frequently to solve problems. Here's some psuedocode to help you understand.
Eg,
Call Macro to get current measurement (in your case, the file size) into variable X
Place current epoch time into variable Z (indicating time of first measurement taken)
LOOP
If Current Epoch Time - Z > 60 seconds then break from loop (because there have been no new measurements in 60 seconds)
Call Macro to get current measurement (file size) into variable Y
If X<>Y then
BEGIN
Store Y into variable X
Place current epoch time into variable Z (indicating the time of next measurement taken)
END
LOOP END
Display "We have finished. It's more than 60 seconds since last measurement (file size increase)"
I do this so often that I created a generic macro to do all this work. I think I pass it the name of the macro which takes a measurement and the amount of time it has to wait, rather than the 60 seconds which is hardcoded above. I think it stores its temporary variables in a dictionary. But you don't have to go to that much work. So here's how I would code a solution like the above to monitor for something:
Call Macro "Monitor-For-Change" with parameters "60,NameOfMacroThatTakesMeasurement"
After trying several approaches I came up with a simple solution that works for me and only pauses until the moment all the pages are scanned.
From Image Capture itself, the only condition I could find that happens as soon as the last page is scanned is that the button "Hide Details" becomes active and not greyed out.
Keyboard Maestro cannot detect a button's mode in a Background App (only in the frontmost active App - which is the question that I started this thread with).
But Keyboard Maestro can see if the button is active or not using a Found Image Condition. Only problem with that is that if I am working on something else while the scan is going on I'd have to make sure the "Hide Details" button is always visible and not hidden behind another window.
Luckily the button is still visible even if Image Capture's window is scaled down as far as it can be.
So, at the point in my Macro where I want the pause (just after the scan is initiated) I have Keyboard Maestro -
Store the current position and size of Image Capture Window (usually right in the middle of my screen).
Move and resize Image Capture to be as small as it will go and put it in a corner of screen (in my case, the far corner of my second monitor)
Wait until the button "Hide Details" is active (using Found Image)
Restore the Image Capture Window back where it was, in the middle of my screen
Play a sound
This is just for the bit in the Macro where I wanted a pause until i.e. this bit:
Is now replaced with this:
I am also going to play around with @Sleepy's suggestion of monitoring a file as I can see that being very useful not only for this but for other Macros.