Programmatically invoke anki?

Hello, I have written a program using Anki and Anki-connect. However, it requires Anki Desktop to be up and running.

to make things convenient for the user, i would like to invoke Anki when my program starts.

Is there a cross-platform way to invoke Anki Desktop if it is not already up and running?

Not a complete answer, but hopefully will help:

import subprocess
import sys

if sys.platform == "win32":
  anki_path = r'C:\Program Files\Anki\anki.exe'
elif sys.platform == "darwin":
  anki_path = '/Applications/'
else: # Linux
  anki_path = "anki"


Note tested

Note that on Windows/Linux at least, the user can install Anki in any folder they want. The above paths are the default paths. If you want the foolproof way, for Windows you probably have to poke around the registry to get the actual installation path (See anki.template.nsi), or you can just ask the user for the path if the default path didn’t work.


My suggestion would be - don’t do this. It will complicate unnecessarily things in your code and won’t give you or the user any significant benefits.
Just check the connection to anki and abort if it fails and give the user a notification that anki isn’t running.

1 Like