Skip to content

Instantly share code, notes, and snippets.

@bebrws
Created July 13, 2019 06:02
Show Gist options
  • Save bebrws/e1523eee27573e63fb539fc22632ea17 to your computer and use it in GitHub Desktop.
Save bebrws/e1523eee27573e63fb539fc22632ea17 to your computer and use it in GitHub Desktop.
Launchbar 6 Note Navigator
on run
tell application "Notes"
set accountList to the name of every account
repeat with currentAccount in accountList
set folderList to {}
repeat with currentFolder in every folder
set noteList to {}
set folderItems to count (notes of currentFolder)
set folderItems to (folderItems as string) & " notes found"
repeat with currentNote in notes of currentFolder
set folderName to get name of currentFolder
set noteName to get name of currentNote
--set folderName to get container of currentNote
set noteCD to get creation date of currentNote
set noteMD to get modification date of currentNote
set noteList to noteList & [{title:noteName, subtitle:(noteMD as string), icon:"com.apple.Notes", actionReturnsItems:false, action:"handle_item", actionArgument:{folderName:folderName, noteName:noteName}}]
end repeat
set folderList to folderList & [{title:(name of currentFolder), subtitle:(folderItems as string), icon:"com.apple.Notes", actionReturnsItems:true, children:noteList}]
end repeat
end repeat
set result to folderList
-- return result
end tell
-- For debugging you can uncomment the following lines and run this in Script Editor
-- set a to {folderName:"A Folder Name", noteName:"A Note Name"}
-- handle_item(a)
end run
on handle_item(_item)
set folderId to (folderName of _item)
set noteId to (noteName of _item)
tell application "Notes"
activate
tell application "System Events"
tell process "Notes"
repeat with i from 0 to the count (rows of outline 1 of scroll area 1 of splitter group 1 of window 1)
try
set currentFolder to get value of static text 1 of UI element 1 of row i of outline 1 of scroll area 1 of splitter group 1 of window 1
on error errorMessage number errorNumber
if errorNumber is equal to -1719 then
set currentFolder to get value of text field 1 of UI element 1 of row i of outline 1 of scroll area 1 of splitter group 1 of window 1
else
log ("errorNumber: " & errorNumber)
error
end if
end try
if currentFolder is equal to folderId then
select row i of outline 1 of scroll area 1 of splitter group 1 of window 1
repeat with t from 0 to the count (rows in table 1 of scroll area 1 of group 1 of splitter group 1 of splitter group 1 of window 1)
if (get value of static text 1 of UI element 1 of row t of table 1 of scroll area 1 of group 1 of splitter group 1 of splitter group 1 of window 1) is equal to noteId then
select row t of table 1 of scroll area 1 of group 1 of splitter group 1 of splitter group 1 of window 1
return
-- no reason to keep repeating over notes
end if
end repeat
-- end timeout
end if
end repeat
end tell
end tell
end tell
end handle_item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment