CopyAnywhere support

This is the support thread for the addon CopyAnywhere

This addon is for power users who want to automate copying and/or modifying note fields in advanced ways. Current 0.2.0 version is still very much in development but I’ve already been using this for over a year and I think the UI is ok enough and functionality bug-free enough now to show in more detail.

CopyAnywhere 0.2.0 features

This is quite a complicated addon as the focus is on complex setups needing to be done once and then set to run automatically. For simple one-time edits edits Advanced Copy Fields or Batch Editing or just plain Anki regex replace is usually faster to navigate through.

But with CopyAnywhere you get fancy progress dialogs

Main modes

Within one note: Edit its fields using other fields, like Advanced Copy Fields but with more edit capability
Source to destinations: Search for other notes with data from a note, then edit that one note with data from the found notes
Destination to sources: Search for other notes with data from a note, then edit each of the found notes with data from the one note

Editing

What you can do

Targets for editing are for now

  • note fields
  • files saved into the collection media folder

File saving uses the same logic as notes, so

  • Within note → write data from one note
  • Destination to sources → search many notes, write data from all into one file
  • Source to destinations → search many notes, write one file for each using data from the initial note

Available data for writing is

  • note fields, tags, note id
  • card data: card id and stats like creation date, first review date, last review data, interval, factor, difficulty, stability, rep count, custom data
  • revlog ease list, factor list, interval list for card

Editing note tags, card custom data and the like is planned for someday… I have need of it myself so it’ll get added at some point.

Advanced editing

How you can do it in more detail

Interpolation is used when constructing the modified field values or file contents. All data mentioned above is available using {{ }} syntax like in Anki card templates. The search string used for querying notes when not in Within note mode is naturally interpolatable.

Variables can be used as intermediate storages of values, if some value needs to repeated into multiple fields. The main use is for constructing complex note search strings from note data.

Regex can be used to modify the values to be stored into variables, fields or files. Any number of regex substitution steps can be chained so quite complex edits are possible. The regex formula and substitution value are also interpolatable.

There are some custom processes that I’ve included pretty much for my personal use that others likely won’t have much use for. With the exception that other Japanese studiers may have uses for the Kana Highlight function:

  • For a given piece of furigana text and a optionally a kanji, split the furigana into individual readings and highlight the kanji and its reading in the text.
  • text: 日本語[にほんご]を 話[はな]している and kanji results in 日[に]<b> 本[ほん]</b> 語[ご]を 話[はな]している
  • the furigana can be merged back together after adding the <b> tag or leaving them split
  • can add tags to indicate readings: <on> 日[に]</on><b><on> 本[ほん]</on></b><on> 語[ご]</on>を<kun> 話[はな]</kun><oku>して</oku>いる

Automation

It's the main point of this

You can either run operations on notes you select in the note browser or you can set operations to run in some or all of the following:

  • On review (requires custom data flag): Operation is run on the specified note type when a card that belongs to it is reviewed.
  • On sync for reviewed cards (requires custom data flag): cards reviewed on other devices are gathered during sync and targeted for operations. This allows operations to be run on notes that you review on mobile and actually would like to run on review there. This requires editing the custom scheduler in the deck settings.
    • If On review is off and On sync is on, then operations will be run on desktop as well for cards reviewed. This option is good when the operation takes annoyingly long when running on review.
    • If On review and On sync are both on, then on desktop the operation is run on review only.
  • On add note usual caveats apply: this means when adding a note using the Add note dialog, through AnkiConnect or other addons calling col.add_note(). Does not apply adding notes from the import dialog or notes added on mobile and then synced to descktop.
  • On unfocusing a selected field in the note editor The selected field could be the field that will be edited or the source field for which some other field (or other notes or files!) are edited.
  • On unfocusing a selected field in the add note dialog otherwise the same as above

The custom data flag required

If you enable copy definitions that should run on review or you use Anki on mobile, you need to add the blow code to the custom scheduler in Anki. To enable fields to update after reviewing on mobile, enable Copy on sync.

  • Open any deck’s settings, at the very bottom in the Advanced section, open Custom scheduling.
customData.again.fc = 0;
customData.hard.fc = 0;
customData.good.fc = 0;
customData.easy.fc = 0;

What it does is sets a flag to the card that the addon checks for when looking for notes whose fields should be updated.

Undoing

Every operatin run adds a custom undo entry, so you get one undo entry even when running multiple operations from the dialog or when multiple operations get on during sync.
Operations done during review get merged into the review undo entry so when you undo your review any operations done are also undone.

Use cases

My own use cases

Personally I use this for various mobile-enabled javascript fancyness

  • Cache revlog information from cards into a note field so I can then use that to display revlog information in the card template on mobile
  • Cache note and revlog information from cards into .json files so I can show information about other linked notes in the card template.
    • My Japanese kanji drawing template shows word examples randomly picked from cached vocab note information
    • My Japanese vocab note shows popovers when clicking kanji that show information from the kanji drawing note/card
  • Collecting linked information between decks of different note types:
    • How many vocab notes contain the kanji of a kanji note
    • What other kanji notes are components of one kanji
  • Includes a custom kanji highlighting function that is really only for Japanese studying. Used for splitting furigana into individual readings, adding html tags that identify which readings are onyomi, kunyomi or jukujikun etc. so I can use CSS to show that information in my Japanese vocab card template…

Examples

Screenshots

A destination to sources operation

Needs a complex query, constructed with a variable

Note query from variable, settings set to return all matching notes

Interpolation editing

You can either type in the interpolation value or right click in the edit field

And pick the field or value from the menu. Each edit input can have different options depending on the mode

Edit input highlighting incorrect interpolation value

Example of saving to file

Note browser context menu shows each operation (I’ve got a bunch of other addons enabled here too):

Running operations manually in the note browser

Check boxes for the operations to be run, select whether to use only selected notes or all (the all options is much faster when you’d otherwise need to select 10k+ notes…)

Operation report. Each operation makes a single undo entry, this batch op created two undo entries.

Todo features

Future wacko plans
  • Ability to edit note tags and card custom data
  • Ability to store values into a new note that will created in the op
  • Split values and actions. So, always first make Variables, then pick what to do with them. So, instead of having 7 or 10 tabs in the future, you have a dropdown to pick where to save a value
  • Custom op chaining. So, instead of having Sources to destinations or Destionations to sources as modes, you always start with basically a Within note op, then you can pick whether to continue on into querying notes. And once you’ve queried notes, you could pick whether to query notes from there again. And at each step you could perform saving into any of the notes gotten so far.
  • Input arbitrary python (but restricted in scope and module usage) and execute that in the op to construct some value. There’s many cases where chaining regex together was either impossible or ludicrously complex when a simple loop and re.sub would’ve been so simple. This would this addon into a kind of addon-making addon.
  • With python script execution, add support for network calls and thus, arbitrary AI calls. Need to update the operations to run async.
5 Likes