Skip to content

Commit 0752774

Browse files
committed
Add sqlite commands
1 parent 5ae520c commit 0752774

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

33
source 'https://rubygems.org'
4+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
45

5-
gem 'gemoji'
6+
gem 'gemoji', github: 'github/gemoji'
7+
gem 'sqlite3'

Gemfile.lock

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
GIT
2+
remote: https://github.com/github/gemoji.git
3+
revision: 55bb37afa4a24e92709ff135a9be4a4f1e79aaef
4+
specs:
5+
gemoji (4.0.0.rc3)
6+
17
GEM
28
remote: https://rubygems.org/
39
specs:
4-
gemoji (3.0.1)
10+
sqlite3 (1.4.4)
511

612
PLATFORMS
713
arm64-darwin-21
814

915
DEPENDENCIES
10-
gemoji
16+
gemoji!
17+
sqlite3
1118

1219
BUNDLED WITH
1320
2.3.16

main.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
require 'gemoji'
2+
require "sqlite3"
23

4+
user = ENV['USER']
5+
paths = Dir.glob("/Users/#{user}/Library/Dictionaries/CoreDataUbiquitySupport/#{user}*/UserDictionary/local/store/UserDictionary.db")
6+
7+
return if paths.nil? or paths.length != 1
8+
9+
db = SQLite3::Database.new(paths.first)
10+
db.execute("DELETE FROM 'ZUSERDICTIONARYENTRY';")
11+
12+
id = 1
313
Emoji.all.each do |emoji|
14+
next if emoji.custom?
415
emoji.aliases.each do |name|
5-
puts name
16+
snippet = ":#{name.gsub('_', ' ')}:"
17+
puts "Adding #{emoji.raw} as #{snippet}..."
18+
item = "{on=1;replace=\"#{snippet}\";with=\"#{emoji.raw}\";}"
19+
system("defaults write -g NSUserDictionaryReplacementItems -array-add '#{item}'")
20+
db.execute("INSERT INTO 'ZUSERDICTIONARYENTRY' VALUES(?, 1,1,0,0,0,0, ?,NULL,NULL,NULL,NULL,NULL, ?, ?,NULL);", [id, Time.now.to_i, snippet, emoji.raw])
21+
id += 1
622
end
723
end
24+
25+
puts "Loading changes..."
26+
system("defaults read -g NSUserDictionaryReplacementItems")
27+
system("killall cfprefsd")
28+
puts "Done!"

0 commit comments

Comments
 (0)