How to get the price of an item in the currently loaded Chrome page


So I can use AppleScript to get the Title of a page using:

tell application "Google Chrome" to return title of active tab of front window

If I have, for example, the page open, I can see the current price is £22.86.

Can I use Applescript (or Javascript) to somehow fetch this value? (It can be the approximate price, it doesn't need to be exact. So, £22 or 22 would be acceptable)

View Source on the page

When I view source for that page I find:

<span class="a-price a-text-price a-size-medium apexPriceToPay" data-a-size="b" data-a-color="price"><span class="a-offscreen">£22.86</span><span aria-hidden="true">£22.86</span></span>

How could I use AppleScript or Javascript to get £22.86 for me? (I want to assign it to a variable called DaPrice)

Using AppleScript is unnecessary as you can use the built-in KM token %FrontBrowserTitle% or %ChromeTitle%

For other browser-related tokens consult the KM wiki here token:WebBrowserTokens [Keyboard Maestro Wiki]

As for your real question you might want to consider using XPath. I’m no expert so search the KM forum for examples of its use.

1 Like

Here’s an example of how to use the xPath to get the price... however, since Amazon is a obscenely bloated website, I am fairly certain there are enough variations for each page that the xPath changes dynamically, and while this works for me, and on the page I use in the example, I HIGHLY doubt this is a reliable method to get prices across multiple pages. But YMMV.

Download Macro(s): Get Amazon Price Using xPath.kmmacros (7.7 KB)


  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 13.5.1
  • Keyboard Maestro v10.2

Thank you , I was not aware!

1 Like

is there a built in token for a copying in image in the front browser? (I didn't see it on the list ) so I guess not

wow thanks for taking the time to have a go. I will attempt to get my head around it!

1 Like

Not that I’m aware of. I highly doubt it since the front browser page could have any number of images.

1 Like

No but since you’re new to this forum you might do well to remember that it’s easy to search which is what I did and came up with this:

I don’t know if that will be useful to you - only you can say. :thinking: