Skip to content

Instantly share code, notes, and snippets.

Created January 26, 2020 07:44
Show Gist options
  • Save mturilin/699a50d0433010708350b8befe4f97a2 to your computer and use it in GitHub Desktop.
Save mturilin/699a50d0433010708350b8befe4f97a2 to your computer and use it in GitHub Desktop.
Converst TextExpander csv to espanso yaml
import yaml
import sys
import csv
# create root yaml
matches = []
# open file
filename = sys.argv[1]
with open(filename, newline='') as csvfile:
csv_reader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in csv_reader:
'trigger': row[0],
'replace': row[1]
# dump results into a file
espanso_root = {
'parent': 'default',
'matches': matches
new_filename = filename[:-4]+".yml"
dump = yaml.dump(espanso_root, encoding='utf-8', allow_unicode=True)
with open(new_filename,'wb') as new_file:
print(F"Created {new_filename}")
Copy link

Kmfernan5 commented Apr 20, 2022

How do you run this? Im getting an error? @mturilin

PS C:\Users***> python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "", line 1, in
NameError: name 'convert' is not defined

Copy link

ernstki commented Dec 20, 2022

@Kmfernan5 Try


Then, assuming it works, look for a YOUR_TEXTEXPANDER_EXPORT_FILE.yml file in the same folder as the CSV export.

If you have trouble with the DRIVE:\ parts, it helps to drag and drop the filename from the Windows file manager into the PowerShell window. The same trick will work on other platforms, e.g., macOS and Linux.

To be clear, I have not tested this script personally—on Windows, or any other platform—I just recognized the error that you made trying to run the script with Python. You need to supply the name of the script to the python program, and then the pathname of the CSV export from TextExpander as an additional argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment