-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappend_to_latest_unshared_note.scpt
39 lines (37 loc) · 1.37 KB
/
append_to_latest_unshared_note.scpt
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
on run argv
-- Get input and format as Notes app expects
set input to first item of argv
set formattedInput to ""
set bulletStart to "b "
set bulletStartLength to (count bulletStart)
if input starts with bulletStart then
if (count input) is bulletStartLength then
set input to ""
else
set input to characters (bulletStartLength + 1) thru -1 of input as string
end if
set formattedInput to "<ul><li>" & input & "</li></ul>"
else
set formattedInput to "<div>" & input & "</div>"
end if
tell application "Notes"
-- Get latest, unshared note. Abandon search past first 10 notes.
set searchLimit to 10
set i to 1
set latestUnsharedNote to null
repeat with i from 1 to searchLimit
set currentNote to note i
if shared of currentNote is false then
set latestUnsharedNote to currentNote
exit repeat
end if
end repeat
if latestUnsharedNote is null then
return "Could not find unshared note in " & searchLimit & " most recent notes"
end if
-- Append the formatted input to the note
set content to body of latestUnsharedNote
set newContent to content & formattedInput
set body of latestUnsharedNote to newContent
end tell
end run