Shorten Steam URL

Hello friends,

How can I take a Steam URL like this:

https://store.steampowered.com/app/1086940/Baldurs_Gate_3/

and shorten it to this (i.e. delete everything after the app number):

https://store.steampowered.com/app/1086940

Thank you!

Hi!

Here's one solution, doing a regex search using the following search string:

\Qhttps://store.steampowered.com/app/\E\d+

Everything between \Q and \E gets treated as a string of literals (a quote), and the \d+ at the end ads on the capturing of any consecutive string of digits.

Shorten Steam URL.kmmacros (16 KB)

And another approach is to write this:

return kmvar.local_Source
    .split("/")
    .slice(0, 5)
    .join("/")

in a Keyboard Maestro Execute Javascript for Automation action.

 


Shortened URL.kmmacros (3.4 KB)

I have a different way to do it, using KM actions only. The first action removes the final "/". The second action removes everything after (and including) the final "/".

In order for the second action to work, you have to open the cogwheel and change the setting to "Last Match." If you also did that for the first action, you could probably remove the "$" character, to save one byte of memory.

Here's a simple regex requiring a single Keyboard Maestro action: