I want to switch languages on Wikipedia with shortcut keys.
For example, I want to jump to a French page when I press a shortcut key that I have decided.
I tried using the action "Click Google Chrome Link" and entering "Français" in the Click Link.
But this fails.
Since specifying the version of Wikipedia, the characters "Français" is displayed in the page.
I'm new to Keyboard Maestro and I'm not sure.
Need to do a more complex setup?
Thank you.
You could use Found Image [Keyboard Maestro Wiki] where a screenshot of the language link is the image to be used. This will work, when the relevant section is on the screen.
Here is something to try and it’s best explained with an example:
The English language page for the Hoover Dam is at: https://en.wikipedia.org/wiki/Hoover_Dam
If you then replace the en in the URL with fr and open it in the browser it loads the French language version of the page at https://fr.wikipedia.org/wiki/Barrage_Hoover
I don’t know how but WP automatically replaces Hoover_Dam in the URL with Barrage_Hoover
I’ve only done this manually, but you could use KM to get the URL from the browser, then perform the replacement in the URL and finally reload the page.
EDIT: just returned to my Mac and tried this out. Here's a KM macro that switches from an English WP page to the French version. It obviously can be extended to prompt for a target language and switch appropriately for example.
I only tried this approach because "why not?" and I wasn't sure it would always work so I'm glad you've found a counter-example. Hopefully the OP will take this on board
because if we look at the 49 languages drop-down on Wiki pages, its language-specific links turn out to be helpfully equipped ( usually ? always ? not sure ...) with the name of specific matching pages, in the form (in this case from the enGirondins page, pointing towards the frGironde page):
or to some other shorter or longer space-separated list of the standard two-letter codes, in the macro below:
(Something that I would usually do in a script, but here's an exercise in sticking to the rich set of blocks and tokens that Keyboard Maestro offers out of the box)
Thank you for your research. I actually want to use languages such as Japanese and Korean, but this method didn't work. Even if I change en in the URL to jp or kr, it will not work.
I actually want to use languages such as Japanese and Korean, but this method didn't work. Even if I change en in the URL to jp or kr, it will not work.
Sorry, my explanation was insufficient.
For example, for English and French, just change the URL from "en" to "fr".
For example, in the Girondin English Wikipedia, as you experimented, changing the URL from en to fr works.
However, try changing the URL manually to jp or ko. It will be failed.
For English and French, the last word of the URL is changed automatically, but for Japanese and Korean it doesn't, so it failed.
In other words, I think that the method of changing the URL is not sufficient, and I still need to click on the "English" or "日本語(This means Japanese)" or "한국어(This means Korean)" text from the language options.
In the first place, isn't KM's action "Click Google Chrome link" an action that clicks the word "Japanese" on the page if I set the word "Japanese"?
and cycles between English Japanese Korean, and back to English.
If I start at:
on first use of the macro with the setting en ja ko
it cycles to:
and on next use, to:
This works because on the Wikipedia pages
the 日本語 link has the attribute lang=ja
the 한국어 link has the attribute lang=ko
and you can achieve these jumps directly with Keyboard Maestro actions like:
Click Front Browser link: //ul/li/a[@lang='ja']
Click Front Browser link: //ul/li/a[@lang='ko']
On the Korean page, for example, the link to the Japanese page is as below. Note the attribute value lang="ja", which suffices to locate and click this link with an XPath expression.
I'm so sorry. I made a stupid mistake. Certainly, as you said twice for me, it is "ja" and "ko". Please excuse my stupidity.
However, a new problem appeared.
I set both the macro, but when I ran it, an error appeared.
The macro that toggles between two languages and the cycles through three languages were both errors.
I'll describe the steps I took.
(1) I downloaded your macro.
(2) Menu of KM → File → Import → Import Macros Safely...
(3) I created a group that fires in Chrome and set it as follows.
However, when I click shortcut key on Wikipedia, this error has appeared.
I also ran it in secret mode to make sure no extensions were interfering, but it's the same.
Chrome version is 114.0.5735.133(Latest at the moment)
Thank you so much...
Not sure what this Gyazo site is, but I won't click on those links to see your images.
If you want us to view images, you can drag image files directly into one of these editing boxes – there's no need to require us to navigate to unknown 3rd party sites.
This is becoming a bit protracted – if you are struggling to make use of the macros supplied, you may be able to save time for yourself and others by constructing your own, less complicated, macro using KM actions like: