How to extract numeric values from an application and compare them?

Hi!

I'm driving crazy here. There's an application where I'm running some KM automations that has a status result text that I need to reuse, but couldn't figure how to extract it and compare it. It works fine with buttons and so.
The text is simple:
XXX items | XXX total

How can I read both XXX values and compare them to see if items is greater or smaller than total?
I really appreciate your help!

image

I”m not sure if I correctly get what you want, but based on your input (as I read it) this could be a starting point:

[test] Compare the Numbers Part of a Text.kmmacros (4.0 KB)

Thank you very much, Tom, for your invaluable help!

Have in mind that 825 (in both cases) is a dynamic number. Imagine a playlist and a selection inside it, or a gallery and a selection. Lists total items and whatever is selected (is not accurate, but just an example).

Basically, I need to check if the dynamic number for "items" is greater, smaller (or equal) compared to the dynamic value of "total numbers" and trigger actions upon.

I've tried your macro, but is not doing anything :frowning:

Note: The text can't be selected. Is text in the app, like a status bar text (you can highlight it with the dictionary for example). Not sure if this matters, but just in case.

Thanks again for your help!

Can you explain? (The macro works fine here, on my Mac.)

Anyway, the point of my macro was to give you a general starting point, for example how to extract the numbers from the text, and how to convert the results into notifications.

Yes, this matters a bit :wink:

This poses another problem: how to get the source data into the macro. This can depend on the scriptability of the source app. Maybe you should explain the whole situation a bit more detailed?

Well, this could be handled by importing the data as a simple list (each pair on a line) and then feeding that list to a similar KM construct as shown above.
But, as said above, a bit more info would probably be OK.


PS:

You have to activate the macro and the containing macro group. Sorry that I forgot to mention that.
It is since KM8 or so that imported macros are deactivated by default.

Thanks, yeah, is enabled and added a few tests for outputs to see if was working with no results neither (does nothing means I bring the app to the front, trigger the key, then it beeps and does nothing -not even triggers the notification for the first variable).

As for the app scripting output, there's not much (to nothing honestly) is a custom app that is reading a gallery and listing elements (that's the totals I need to compare; it reads a remote source and the status bar displays those items vs totals so I know if needs update.

A better test would be: swap to iTunes, then enable the status bar. Go to any playlist you have and select some items (not all). I would need to read those numbers from the status bar.

Added some notifications (illustrative image):

Thanks!

I've been thinking... perhaps it doesn't work, because this is not a single line:

835 items | 835 total

but instead, individual "fields", being 835 one, items another, the pipe another, and so on... as the text is not selectable, I've assumed a single line on my own

No. Before going any further we should assure that my “[test]” macro from above works on your side too. If it doesn’t, then something is wrong with your setup.

As a reminder: Make sure the macro is enabled and the macro group is enabled too. If you don’t know what I’m talking about, please have have a look at the KM Wiki, e.g. Macro Groups.

Once we have a macro that works on both sides (your Mac and mine), then we can proceed.


PS: The information you provided with your recent posts is valuable and will not be lost.

I've made other complex macros that are working just fine. What did you test this against to? So I can do the same test.

I tested it against my brand-new iMac 27”, but I’m pretty positive that it will work also on my 2017 MBP and on my 2012 MacMini :wink:

Otherwise, there is no software to test it “against”. The input is provided in the first action of the macro. The macro is self contained.

You are using KM8, right?

Hi, thanks - I didn't knew the macro was self-contained. I was trying to trigger it via shortcuts inside the app itself. As standalone it works fine, I just need to know how to read the text from the app (that's why I was quoting iTunes as an example, just need to find a way to isolate text (not selectable) from an app.

Yes to KM8 :slight_smile:
I need the against part :smiley:

how custom is your application? can you modify the original application to give you the data in a different format?

alternatively, if it is working on files on your computer, could you replicate the counting functionality with keyboard maestro so you get the counts in a usable format?

Well, you can't easily get it currently, but when version 9 is released, you will be able to just OCR it off the screen:

image|301.5x535

Something to look forward to I guess…

4 Likes

Thank you all!

@peternlewis this seems to be exactly what I needed, thanks! Will have to wait for V9, I guess. What surprises me is that KM is able to read custom text from buttons (I have some conditionals running on dynamic button texts which are working great) so assumed it could simply read simple text from a form too. Thanks for the guidance!

@vincent_ardern the app is a homemade app (I didn't made it) that queries remote information and displays results in a simple status bar (like iTunes, Chrome when enabled, Adobe products, and so on). I can't reshape the data nor query the results on my own, and all goes to that status bar. Seems OCR would be the way

Hey Gonza,

Chances are that data can be scraped from the UI with AppleScript UI-Scripting, but I'd have to see the app.

-Chris