-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget_journal-prompt.js
65 lines (53 loc) · 1.87 KB
/
widget_journal-prompt.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
60
61
62
63
64
65
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: gray; icon-glyph: smile-wink;
// 📁 https://github.com/huaminghuangtw/Evergreen-Lists
const utils = importModule("utils");
let widget = new ListWidget();
widget.backgroundColor = Color.black();
widget.useDefaultPadding();
let filename = "💭 Journal Prompt";
let fileContent;
try {
fileContent = await new Request(
`https://raw.githubusercontent.com/huaminghuangtw/Evergreen-Lists/main/${encodeURIComponent(
filename
)}/${encodeURIComponent(filename)}.json`
).loadString();
} catch {
let fm = FileManager.iCloud();
let folderPath = fm.joinPath(
fm.bookmarkedPath("Second-Brain"),
"EvergreenLists"
);
let jsonFile = utils
.getAllFilesByExtension(folderPath, "json")
.find((file) => file.includes(filename));
fileContent = fm.readString(jsonFile);
}
let reminders = JSON.parse(fileContent).reminders;
let randomJournalPrompt = utils.getRandomItem(
utils.getRandomItem(
reminders.filter(
(r) => r.subtasks && r.subtasks.length > 0 && !r.flagged
)
).subtasks
).name;
let text = widget.addText("“" + randomJournalPrompt + "”");
text.centerAlignText();
text.textColor = Color.white();
// http://iosfonts.com
text.font = new Font("IowanOldStyle-BoldItalic", 20);
text.minimumScaleFactor = 0.1;
text.textOpacity = 1;
widget.url =
`shortcuts://run-shortcut?` +
`name=${encodeURIComponent("Gemini - Generate Content")}&` +
`input=${encodeURIComponent(
JSON.stringify({
prompt: "If you were in my shoes, how would you answer this question? Get specific and be brief. Use less than 100 words.",
content: randomJournalPrompt,
})
)}`;
config.runsInWidget ? Script.setWidget(widget) : widget.presentMedium();
Script.complete();