-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathgetSmartGroupList.js
57 lines (45 loc) · 1.79 KB
/
getSmartGroupList.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
'use strict';
function run(argv) {
// read environment variables
ObjC.import('stdlib')
let env = $.NSProcessInfo.processInfo.environment;
env = ObjC.unwrap(env)
let selectedDbUUID
let filterOutGroup
if ("selectedDbUUID" in env) { selectedDbUUID = $.getenv('selectedDbUUID') }
if ("filterOutGroup" in env) { filterOutGroup = $.getenv('filterOutGroup').toLowerCase() }
if ("ignoredDbUuidList" in env) {
let ignoredDbUuidList = [];
let tempList = $.getenv('ignoredDbUuidList').split(",");
for (let i = 0; i < tempList.length; i++) {
ignoredDbUuidList.push(tempList[i].replace(/^\s+|\s+$/g, ''))
}
}
let DNt = Application("DEVONthink 3");
let allDB = DNt.databases
// if selectedDbUUID exists, only search in selected db.
if (typeof selectedDbUUID !== 'undefined') {
allDB = { "0": DNt.getDatabaseWithUuid(selectedDbUUID) }
}
let allResult = []
for (let dbIndex in allDB) {
let theDbUUID = allDB[dbIndex].uuid()
// if selectedDbUUID not exists and theDbUUID in ignoredDbUuidList, ignore the db
if ((typeof selectedDbUUID == 'undefined') && (typeof ignoredDbUuidList !== 'undefined') && ignoredDbUuidList.includes(theDbUUID)) {
continue
}
let smartGroupList = allDB[dbIndex].smartGroups()
for (let sgIndex in smartGroupList) {
let item = {
title: smartGroupList[sgIndex].name(),
subtitle: allDB[dbIndex].name(),
arg: smartGroupList[sgIndex].uuid()
}
allResult.push(item)
}
}
if (allResult.length == 0) {
return JSON.stringify({ "items": [{ "title": "No SmartGroup..." }] });
}
return JSON.stringify({ "items": allResult });
}