-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
59 lines (43 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const alfy = require("alfy");
const Database = require("better-sqlite3");
const alfredNotifier = require("alfred-notifier");
alfredNotifier();
// Get ref to user input
const { input } = alfy;
const cached = alfy.cache.get(input);
// // alfy.log(`cached: ${cached}`);
if (cached && cached.length) {
return alfy.output(cached);
}
// Get path to database
const homeDir = require("os").homedir();
const PATH_TO_DB = `${homeDir}/Library/Group Containers/group.com.apple.notes/NoteStore.sqlite`;
// Open notes database
let db = new Database(PATH_TO_DB);
// SQL Queries
const GET_UUID = "SELECT z_uuid FROM z_metadata";
const GET_ROW = `SELECT ztitle1,zfolder,zsnippet,zmodificationdate1,z_pk FROM ziccloudsyncingobject WHERE ztitle1 IS NOT NULL AND zmarkedfordeletion IS NOT 1 AND ztitle1 LIKE "%${input}%"`;
// Get uuid string required in full id
const [{ Z_UUID: uuid }] = db.prepare(GET_UUID).all();
const allRows = db.prepare(GET_ROW).all();
// Format via Alfred supported properties
const makeAlfyOutput = arr => {
if (arr && arr.length) {
return arr.map(itemObj => {
const { ZTITLE1: title, Z_PK: uid } = itemObj;
return {
title,
uid,
arg: `x-coredata://${uuid}/ICNote/p${uid}`,
icon: {
path: "./note.png"
}
};
});
}
return [];
};
const alfyOutput = makeAlfyOutput(allRows);
alfy.cache.set(input, alfyOutput, { maxAge: 3600000 });
alfy.output(alfyOutput);
db.close();