Pause until action is complete

I want to perform a series of actions within a program; each takes some time, but the time varies unpredictably. The actions are 1)Sync; 2)save; close window. If I just put those three actions in a row in the macro nothing works; the first action doesn’t happen and the computer just sits there until I cancel out of the macro. I’m assuming that the second command is interfering with the completion of the first.

How can I tell Keyboard Maestro to Sync and wait until that process is finished; then save and wait until that process is finished; finally close the window or whatever?

The program is iBank, but I’m sure this sort of thing comes up often. I’m sure it’s simple, but I’m a newbie and can’t find the answer.

The key is for KM to know when the Sync is complete.
What do you see on your iBank screen that tells you sync is complete?

Use this with the KM Pause Until action.

If you can't figure anything out, you can always use KM action "Prompt User for Input".
It will pause the macro there until your click the OK button.

Thanks for quick response! There’s a little message box that announces the steps and finally says "Last updated on [date,time]. I am not sure how to tell KM where to find this message. I’ve looked at all the conditions without finding one that looks like it would help. It would be great if, for instance, all other menu items were disabled until the current one was finished, but that doesn’t seem to be the case visually. The save item isn’t greyed out while the sync one is running, but I’ll try it out as if that were the case, just for an experiment.

I tried this experiment:
Select Sync
Pause until a menu item Save is enabled
Alert 'Syncing Done’
Select Save
Pause until a menu item Close is enabled
Alert 'Saving done’
Select Close

It was partly successful. Syncing started and immediately the Alert showed up; I waited until I saw that syncing was complete, then manually ok’ed out of the alert
Saving started, and this time the alert didn’t show up until the saving process had finished. I ok’d and the window closed. I removed the second alert (the one about saving) and the window closed appropriately once saving had finished.
So the issue is how to tell KM that syncing is still going on. I suppose the difficulty is that syncing happens online, and is thus not a system process; while saving is indeed a system process, so it’s easy for KM to see. A kludge would be to leave that alert in my macro and move on manually for that step. What I’d like to be able to do is start the macro and leave it to sync and save each of 2 files and then quit the program, all without my having to sit and wait while the online part (and indeed the saving) takes however long it takes today.

Is this in a popup window, or just displayed on the app window?

You can try this:

Create a TEST macro, and leave it visible while you go through the manual steps.

The macro will show the results without running it as you go through the manual steps.
If the Window Title changes during/after sync, you can use that in a Pause Until action.

Nice idea; but the macro just shows the actual window title, which in this case is the file name, and doesn’t change during any process. So that won’t work.

Well, that leaves these options, AFAIK:

  1. Set a Pause time you know will always be sufficient.
  2. Using Pause Until “The Screen does not contain” the image shown during sync.
  3. Using the Display Alert
  4. AppleScript – can your app be controlled by AS? Maybe it can tell the app to “sync” and wait until completed, then do the other actions.

If Sync is a menu option, then often it will be disabled in the menu until the sync is completed, and thus Pause Until menu Sync is enabled may be am option.

How do you know when the sync is completed? If you’re sitting in front of the Mac, how can you tell? Keyboard Maestro can presumably tell the same way.

1 Like

Hey William

I’d take a couple of approaches.

(01) I’d open the Activity Monitor.app and then run the sync operation — all the while looking for a process specific to syncing.

If there is process that starts and stops during syncing then your task is pretty simple. You can run a shell script on a timer to inspect the running processes for your sync process. When it’s gone you can proceed.

(02) System Events sees more windows than Keyboard Maestro.

Run this from the Script Editor.app when iBank is syncing and the indicator window is open.

tell application "System Events"
  tell application process "iBank"
    name of windows
  end tell
end tell

Look for a unique window name for the indicator window.

Run it again when the indicator window is gone.

See if indicator window name is gone.

If System Events sees the window you can do something like:

tell application "System Events"
  tell application process "Finder"
    if "Downloads" is in name of windows then
      return "true"
    else
      return "false"
    end if
  end tell
end tell

Tell Keyboard Maestro to run it every 15 seconds until it returns “false”, and give it a timeout value in case of error.

I looked briefly online, and it doesn’t’ appear that iBank itself is scriptable — so you’re stuck with these sorts of workarounds.

That’s all I can think of at the moment without having my hands on the app.

-Chris

Good idea. Unfortunately it didn’t occur to the iBank folks to disable the Sync menu item while syncing was going on, and if you choose it while syncing is going on, it just messes up the sync process.

I know that syncing is done because a little status bar type window-ette at the top of the main window announces what’s going on, with a progress bar to show progress. Once that’s done, the status area says "File updated [date,time]. This isn’t a separate window at all, just an indicator in the main window. I haven’t been able to locate any process or anything at all that corresponds to the contents of that indicator, so I don’t know how to tell KM what to look for. Perhaps I’m just reduced to clicking out of the KM alert when it’s time. It’s still a bit of a timesaver.

In that case, perhaps the best you can do would be to use the Found Image condition, so Pause Until not image is on the screen.

And I would definitely report the Sync menu issue to iBank, because that’s pretty poor.