Combine shortcuts

Hi, everyone! Does anyone know a way to combine different shortcuts? When editing my cards, sometimes I need to apply 3 different elements, which requires me to type a lot of shortcuts. When I want to underline, change color and apply bold, I need to type Cmd+b, cmd+u and Cmd+k (shortcut I customized to change color). Is there a way to create a single shortcut to make all these changes at once? Thank you!

image

If you never use italic you could maybe add this to the styling section of your notes:

i {
text-decoration: underline;
font-weight: bold;
color: blue;
font-style: normal;}

Or you could also try using this addon: Custom Styles (font color, background colour, classes) - AnkiWeb

3 Likes

Keyboard Maestro comes to mind for automation and to avoid repetition.

Thank you! Is this how it’s done?
image

Thank you! Is there a free tool?

Yes! Now if you select a portion of text and click Cmd+I such text should be displayed as “bold, blue and underlined” instead of italic
(only while reviewing, in the editor it will still be displayed as italic)

1 Like

Is there a free tool?

I don’t know. Since Keyboard Maestro fills, tags and formats the content of some of my Anki notes, I never looked at alternatives. I doubt there are equivalent programs for Mac.

1 Like

It WORKED!
editor:

reviewing:

Thank you so much, you saved me a lot of time :smiley:
Just a question, I can keep creating combinations, right? Like… if I want to create shortcut only for blue+bold (no underline), how would it be?

In theory you can, in practice there are some limitations to it.
Besides <i></i>, you can also modify the way <b></b>, <u></u> and their combinations (e.g. <b><i></i></b>) are displayed, but that’s the end of it (as far as I know).
That means there are only three “1 click” combinations you can create and, if my math is right, only six “2 clicks” combinations.
This also comes at the price of losing these tags’ standard function: for example, with the css code I have given you you lost the <i></i> tag’s standard function to make the text be displayed as italic.

If you want to add many combinations, I strongly suggest checking the addon I linked above! It allows to create how many “1 click” combinations as you want.
It is very powerful, but you have to configure it yourself.

image

I suggest using “classes” to format your text.
E.g. you could create a class named “blue+bold” and add this to the “styling of class” section of addon’s configuration menu:
font-weight:bold
color:blue

You could also leave “styling of class” empty and instead add this to the styling section of your notes:
.blue+bold{
font-weight:bold;
color:blue
}

It does not really make a difference, except that in this case, to modify the way the “blue+bold” class is displayed, you have to modify the note’s template and not this addon’s configurations. This allows the styling to be note-type specific and also means you can modify it from mobile.

[The addon comes with a lot of pre-set styles, backgrounds etc.
They are all already assigned to a shortcut. So if some shortcut you create doesn’t work it might be because of overlapping. This can be solved by deleting/disabling such pre-sets or changing their shortcuts]

Ask if you need help on how to configure the addon

2 Likes

Hey @jcznk, I’ve installed the add-on and added an entry for blue-bold, with the code you sent me. But then a warning appears saying: This add-on will NOT work with these note types:

  • Básico

  • Básico (cartão invertido opcional)

  • Básico (digite a resposta)

  • Básico (e cartão invertido)

  • Básico-21a7c

  • Omissão de Palavras
    I do use these note types and therefore I need to have the extension working with them. What can I do? Thanks!
    And another question, I read the text on the download page, and it’s a little scary. What I understood is that if I do something (I don’t know what), I might loose all the editing I do, and that I shouldn’t use the add-on if I have no coding knowledge, which is my case. Is there any thing I have to do other than installing the add-on and adding the code you posted here?

image

  • For many functions of this addon to work, a small piece of code needs to be added to the top of the styling section of your note types: @import url("_editor_button_styles.css");
    You can add it manually, or you can click on the “yes” button and the addon will update all your note-types for you.
    I used such function a lot of times and never had any problems, nor have I heard of any, but it’s always a good idea to do a backup before batch-editing the templates.

[This piece of code is actually not needed if you plan to use the addon to only add classes, editing the way they are displayed by adding code to the styling section of your notes (the .blue+bold{font-weight:bold; color:blue} method I talked about in the last post)
Keep in mind, though, that this means you need to edit each note-type’s styling section one by one.
(If you don’t add @import url("_editor_button_styles.css"); the addon will keep notifying you that it won’t work until you update your templates, which is not true if you plan to only use this method. That said, I would still add such piece of code, as it can always be useful, e.g. it gives you access to all the pre-set styles etc.)]

  • About the “losing editing” part: there are a couple of things that need to be understood, but they are fairly simple.
    The way this addon works, at least the methods I explained to you, is that it allows you to add a custom class to some portion of text, then editing the way this class is displayed (either via note-templates’ styling section or this addon’s configurations).
    E.g.
  1. you might have this text: “This is an example”.
  2. You use this addon to add the “blue+bold” class to the word “example”.
  3. The html code of this text will now be: “This is an <span class="blue+bold">example</span>”.
    Now, while you are in the reviewer, Anki will see that the word “example” is wrapped in the “blue+bold” class, and will display it as blue and bold.
    In Anki, classes work a little bit differently than tags (<i></i>, <b></b>, etc.).
    The most notable difference is probably that if you copy and paste some text, the tags will be kept but the classes will be lost.
    E.g. if I have some text whose html is “This is <b>an</b> <span class="blue+bold">example</span>”, after you copy and paste it, the text’s html will be “This is <b>an</b> example”: the “bold” tag is kept, while the “blue+bold” class is gone. So there’s the risk you might lose some of your styling, if you’re not careful.
    This is easily preventable by copy-pasting the html code instead of the ‘plain’ text. To do this, you first need to open the html editor (I don’t know the shortcut for mac, but you can access it by clicking on the </> button in the card editor)
    If you limit your usage of this addon to the methods I explained to you, there should not be much else to understand, I believe
1 Like

THANK, @jcznk . I thought something wrong happened here, uninstalled Anki and downloaded again the 1.1.50 version. I installed again the add-on, and got this error message:
Informações de Depuração:
Anki 2.1.50 (6718e678) Python 3.9.7 Qt 6.2.3 PyQt 6.2.3
Platform: Mac 11.6.5
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2022-03-31 06:27:11
Extensões possivelmente envolvidas: ⁨Custom Styles font color background colour classes⁩

Caught exception:
Traceback (most recent call last):
File “/Users/gabrieldias/Library/Application Support/Anki2/addons21/1899278645/main_window.py”, line 35, in on_settings
dialog = MainConfDialog(getconfig())
File “/Users/gabrieldias/Library/Application Support/Anki2/addons21/1899278645/confdialog/init.py”, line 52, in init
self.init_tables()
File “/Users/gabrieldias/Library/Application Support/Anki2/addons21/1899278645/confdialog/init.py”, line 216, in init_tables
self.set_table(self.bo.tw_active, self.active)
File “/Users/gabrieldias/Library/Application Support/Anki2/addons21/1899278645/confdialog/init.py”, line 222, in set_table
widget.setSelectionBehavior(QTableView.SelectRows)
AttributeError: type object ‘QTableView’ has no attribute ‘SelectRows’

Is this a problem that will prevent me from using the add-on? Thanks!

I actually don’t know, sorry!
Maybe the addon has not been ported to Anki 2.1.50 yet

You should probably contact the author of the addon and ask them

1 Like

I will do it, thanks!

I thought about this a bit better and I realized that the best option for you should be to use “inline styles”, not classes.
They have two advantages: 1. the text appears stylized in the editor too, not just in the reviewer 2. you can copy-paste the text without the styles being lost.
This would be an example of an inline style’s html: <span style="font-weight:bold; color:blue">text</span>

Unfortunately, I cannot seem to use the addon to add inline styles, even though it theoretically offers such function. The same configurations that worked in Anki 2.1.22 do not seem to function in Anki 2.1.49.
I contacted addon’s author about it, so let’s see

To achieve this without an external program, you can group shortcuts using AppleScript and wrapping it with the (unfortunately named) Shortcuts app that’s bundled with MacOS. See here for a shortcut that activates the three shortcuts keys your mentioned:

https://www.icloud.com/shortcuts/828dc43001d24dd0b4c37a0bda84de8d

Once installed you can then assign the shortcut to its own shortcut key in System Preferences > Keyboard > Shortcuts > Services (at the bottom of the list)

@jcznk I downgraded to 2.1.49 (I was using the 2.1.50 beta version). And I changed all my notes to the same type (Basic) -I had cards of many different types (I don’t know why, but I feel this standardization had a positive effect on Anki) . The blue+bold+underline styling is working fine (with the code you sent me). This is already enough for me to keep my studies without wasting too much time. Now the only solution I need is this way to create more combinations (like blue+bold, or red+bold…). In case you find some interesting tool, please let me know. But don’t bother wasting your time to find solutions, right know I have the basic means to keep studying.

Thank you! I appreciate how much you guys here are always willing to help.

It says that “This app is available only on the App Store for iPhone and iPad.” Do you know an app for Macbook?

Hey @jcznk do you see any reason why “única interrupção” is black? I applied Cmd+b, but the color didn’t change (I repeated the code you sent me, using “b”. Thanks!

I tried your code and it seems to works fine.
In your case there’s probably some inline code that is interfering with it. Probably some html that says that those two words (and possibly some other portion of text) are black.
Something like: This is <font color="#0000ff">an</font> example

Such inline pieces of code are sometimes added when copy-pasting text, especially from sources other than Anki. They get the precedence over what’s specified in the note template.

Try these:

  1. select the entire text, then set its color to black (pure black, the one with the hex code #000000). Since #000000 is Anki’s default, doing this should remove all inline code about color and is usually enough to fix the problem
  2. if it doesn’t fix it, try removing all formatting (eraser button), then add again the bold/italic tags and check if it works
  3. if none of these work, please open the html editor and post a screenshot here