-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist-notes.js
More file actions
executable file
·66 lines (61 loc) · 1.57 KB
/
list-notes.js
File metadata and controls
executable file
·66 lines (61 loc) · 1.57 KB
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
60
61
62
63
64
65
66
#! /usr/bin/osascript -l JavaScript
// -*- mode: JavaScript -*-
function findFolderNamed(app_or_folder, name) {
let folders = app_or_folder.folders();
// I don't know why for (let x of folders) doesn't work, but it doesn't.
// Need to explicitly index the folders array.
for (let i = 0; i < folders.length; i += 1) {
if (folders[i].name() === name) {
return folders[i];
}
}
return undefined;
}
function parseArgv(argv) {
let config = {
projects: true,
areas: false
};
if (argv.length === 0) {
return config;
}
if (argv[0] === '-a') {
config.areas = true;
config.projects = false;
}
if (argv[0] === '-p') {
config.projects = true;
config.areas = false;
}
return config;
}
/* exported run */
function run(argv) {
let config = parseArgv(argv);
let notesApp = Application("Notes");
if (! notesApp) {
console.log("Couldn't find Notes");
return;
}
notesApp.includeStandardAdditions = true;
notesApp.strictPropertyScope = true;
notesApp.strictCommandScope = true;
notesApp.strictParameterType = true;
let personalFolder = undefined;
personalFolder = findFolderNamed(notesApp, "Personal")
let srcFolder = undefined;
if (config.projects) {
srcFolder = findFolderNamed(personalFolder, "Projects");
}
if (config.areas) {
srcFolder = findFolderNamed(personalFolder, "Areas of Focus");
}
let names = [];
let srcFolders = srcFolder.folders();
for (let i = 0; i < srcFolders.length; i += 1) {
let f = srcFolders[i];
names.push(f.name());
}
names.sort();
return names.join("\n");
}