forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsidenotes-create-note.applescript
executable file
·73 lines (59 loc) · 2.07 KB
/
sidenotes-create-note.applescript
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
67
68
69
70
71
72
73
#!/usr/bin/osascript
# Dependency: Requires SideNotes (https://apptorium.com/sidenotes)
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title SideNotes create
# @raycast.mode silent
# @raycast.packageName SideNotes
# Optional parameters:
# @raycast.packageName SideNotes
# @raycast.icon images/sidenotes.png
# @raycast.argument1 { "type": "text", "placeholder": "Note", "optional": true }
# @raycast.argument2 { "type": "text", "placeholder": "Folder", "optional": true }
# Documentation:
# @raycast.description Create a new note within the selected or the first SideNotes folder.
# @raycast.author Marcel Bochtler
# @raycast.authorURL https://github.com/MarcelBochtler
on run argv
if application "SideNotes" is not running then
log "SideNotes is not running"
return
end if
tell application "SideNotes"
set note_content to item 1 of argv
set folder_name to item 2 of argv
# Create a folder if none exist
if (count of folders) is 0 then
if folder_name is "" then
make new folder with properties {name:note_content}
else
make new folder with properties {name:folder_name}
end if
end if
set folder_index to my index_of_folder(folder_name, folders)
if folder_index is -1 then
# Folder not found. Create one if the name is given.
# Otherwise create the note in the current or the first folder.
if folder_name is not "" then
set target_folder to make new folder with properties {name:folder_name}
else
if current folder is missing value then
set target_folder to first folder
else
set target_folder to current folder
end if
end if
else
set target_folder to item folder_index of folders
end if
set created_note to make new note in target_folder at 1 with properties {text:note_content}
open folder target_folder note created_note
log "Note created in folder " & (name of target_folder)
end tell
end run
on index_of_folder(folder_name, folder_list)
repeat with i from 1 to the count of folder_list
if name of item i of folder_list is folder_name then return i
end repeat
return -1
end index_of_folder