Skip to content

Instantly share code, notes, and snippets.

@ashfurrow ashfurrow/convert.rb
Created Feb 18, 2019

Embed
What would you like to do?
Converting TextExpander Exports to macOS shortcuts
#!/usr/bin/ruby
# Instructions:
# Go to https://app.textexpander.com/settings/export and download all the CSVs into the same directory as this script.
# TextExpander's Export doesn't produce valid CSV files (lol) so make sure to open them with Numbers and re-export them.
require 'csv'
plist = <<~PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
PLIST
Dir["./*.csv"].each do |filename|
contents = File.read(filename)
puts "Opening #{filename}"
csv = CSV.parse(contents)
csv.each do |row|
if row[1].nil?
# Why? We may never know.
puts "Skipping #{row[0]} because its entry is empty."
elsif row[1].include?("<")
# TextExpander has this annoying habit of using HTML for rich text snippts,
# something I never used but managed to worm its way into a few snippets.
# Skip them.
puts "Skipping #{row[0]} entry because it's rich text."
else
plist += <<~PLIST
<dict>
<key>phrase</key>
<string>#{row[1]}</string>
<key>shortcut</key>
<string>#{row[0]}</string>
</dict>
PLIST
end
end
end
plist += <<~PLIST
</array>
</plist>
PLIST
File.write("output.plist", plist)
puts "Review the output above, and drag output.plist into the System Preferences' Keyboard settings (Text subpanel)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.