sballin / alfred-search-notes-app

Use Alfred to quickly open notes in iCloud/Apple Notes.
https://www.alfredforum.com/topic/11716-search-appleicloud-notes/
MIT License
510 stars 24 forks source link

Selected note doesn't open #33

Closed bowernite closed 3 years ago

bowernite commented 3 years ago
  1. Search for a note with n <query>
  2. ↵ Enter
sballin commented 3 years ago
bowernite commented 3 years ago

Output Log

[13:03:11.069] Search Notes[Script Filter] Script with argv 'golf' finished
[13:03:11.100] Search Notes[Script Filter] {
    "items": [
        {
            "title": "Golfing",
            "subtitle": "Notes",
            "arg": "x-coredata://4E224CCE-DD8D-417D-B922-DD0E9F4F45EA/ICNote/p257?golf",
            "quicklookurl": null
        },
        {
            "title": "Golf Club Buying",
            "subtitle": "Archive",
            "arg": "x-coredata://4E224CCE-DD8D-417D-B922-DD0E9F4F45EA/ICNote/p156?golf",
            "quicklookurl": null
        }
    ]
}
[13:03:21.001] Search Notes[Script Filter] Processing complete
[13:03:21.002] Search Notes[Script Filter] Passing output 'x-coredata://4E224CCE-DD8D-417D-B922-DD0E9F4F45EA/ICNote/p257?golf' to Run NSAppleScript
[13:03:21.136] Search Notes[Run NSAppleScript] Processing complete
[13:03:21.149] Search Notes[Run NSAppleScript] Passing output '' to Run Script
sballin commented 3 years ago

Thanks, that all seems normal... Are you viewing your notes in gallery mode? I made this workflow with list mode in mind, but can reproduce what you report when I switch to gallery.

bowernite commented 3 years ago

Yup, I’m in gallery mode

(You’re referring to where notes are shown as tiles instead of in a list, right?)

sballin commented 3 years ago

You can try pasting the following to replace the script that has the description "Show note/folder or create note". I'm not a big fan of the delay required for it to work, and it doesn't work if the Notes in-app search is active.

on alfred_script(q)
    tell application "Notes"
        if q contains "/ICNote/p" then
            activate
            tell application "System Events" to key code 53 -- escape
            -- Show user requested note
            -- Get note id which is first item in q
            set noteID to text 1 thru ((offset of "?" in q)-1) of q
            show note id noteID in default account
            show note id noteID in default account
            delay 0.3
            tell application "System Events" to key code 76 -- return
        else if q contains "/ICFolder/p" then
            -- Show user requested folder
            -- Get folder id which is first item in q
            set folderID to text 1 thru ((offset of "?" in q)-1) of q
            show folder id folderID in default account
            show folder id folderID in default account
        else
            -- Create new note from user query
            -- Move from any other folder/state to default "Notes" folder
            show default folder in default account
            show default folder in default account
            tell application "System Events"
                tell process "Notes"
                    click menu item 1 of menu 3 of menu bar 1 -- File, New Note
                    set clipboardOld to the clipboard
                    set the clipboard to q
                    click menu item 6 of menu 4 of menu bar 1 -- Edit, Paste
                    click menu item 1 of menu 5 of menu bar 1 -- Format, Title
                    key code {36, 36} -- press enter twice
                    delay 0.1
                    set the clipboard to clipboardOld
                end tell
            end tell
        end if
    end tell
end alfred_script
bowernite commented 3 years ago

Yeah, that isn't super bulletproof either -- it still doesn't work when the Notes app is already on a different note (first bullet point in the original issue description above).

Anyways, I appreciate you trying to help me out here -- I think I'll just switch to the list view for now for the path of least resistance (I may switch to something like markdown files or Bear at some point anyways).

~

As a side note, do you have any advice and where to find documentation on writing AppleScript? I'd love to be able to debug/write AppleScript and solve these problems for myself, but the whole thing is super daunting and confusing to me right now:

sballin commented 3 years ago

Applescript is unfortunately not very well documented. I mostly learned by googling, dictionaries, and looking at unrelated scripts people have written. There's a paid app called Script Debugger which helped me out when I was new to it. One very handy command is "get properties of blah". For UI scripting the Xcode Accessibility Inspector is very useful.