raycast / extensions

Everything you need to extend Raycast.
https://developers.raycast.com
MIT License
5.45k stars 3.15k forks source link

[Apple Notes] Action to create a deep link to open a specific note in Notes #5658

Closed dreasan closed 1 year ago

dreasan commented 1 year ago

Extension

https://www.raycast.com/tumtum/apple-notes

Description

I really appreciate this extension, and use it quite a bit to get to my notes. One thing that would make it even better would be an action to be able to create a deep link similar to the one that can already be created to search for notes:

raycast://extensions/tumtum/apple-notes/index?fallbackText=Recipe

The link searches for all notes containing recipes. Nice!

Additionally, I would now want to be able to link to notes directly and open them. Therefore, an idea:

Could we create a new action in the note search results to immediately create a deep link to open the note in Notes?

raycast://extensions/tumtum/apple-notes/open?fallbackText=Best%20Chocolate%20Chip%20Cookie%20Recipe

notes://showNote?identifier=UUID

EDIT: Changed to Apple notes URL scheme. See comments below, for an explanation, why the Raycast URL scheme was suggested at first.

Who will benefit from this feature?

All users who would want to link to notes from other applications (writing tools, task managers etc.).

Anything else?

No response

raycastbot commented 1 year ago

Thank you for opening this issue!

πŸ”” @tumispro @ron-myers @mathieudutour @StevenRCE0 you might want to have a look.

πŸ’‘ Tip: Once the issue is resolved, comment @raycastbot close this issue to close it.

StevenRCE0 commented 1 year ago

I think it's beyond Raycast Deeplink's purpose and seems like a detour. You may have a look at a discussion about Apple Notes URL schemes which is likely to be a better way to jump into some specific note.

SKaplanOfficial commented 1 year ago

Maybe it'd be good to have an action to copy the note's URL, or even just its ID? It's not very straightforward to get that info from the Notes app itself, so Raycast could help here without making a whole new URL scheme.

dreasan commented 1 year ago

Yup, I agree with @SKaplanOfficial.

My initial request/idea was based on the false assumption that the Apple Notes URL scheme is not working (anymore), based on another discussion and a failed self-test.

However, the link you provided to the Apple forum discussion made clear that I used a wrong scheme, and it actually works. I could now successfully open a note by using:

notes://showNote?identifier=UUID

Therefore, I would amend the initial request toward the use of the Apple Notes URL scheme.

Meaning, the notes search result list (Search Notes command) should offer an Action to get the note UUID (Copy Note ID). Or, even better: The URL to open the note (Copy Note Link). The ID is probably perhaps already known to Raycast at that point (this needs to be clarified).

I believe it would be useful, especially since it opens the door to easy internal linking in notes without first sharing these via iCloud. And as @SKaplanOfficial mentioned, these IDs are not directly accessible anywhere else in Notes.

StevenRCE0 commented 1 year ago

It makes sense and is quite easy to implement. I'm working on it!

Update: It's easy to get the UUID from notes inside sqlite database. However, some notes are only retrieved via AppleScript approach, which UUID is not accessible (the id property is not what we need). So, it won't work on those notes (basically deleted ones).

StevenRCE0 commented 1 year ago

Here I would start a discussion:

SKaplanOfficial commented 1 year ago

The script here uses AppleScript and sqlite3 to get the selected note URL with AppleScript -- shouldn't be too difficult to modify this to get the deeplink of any particular note. Still doesn't work for "On This Mac" notes, but it seems like those just don't support deeplinks at all.

I think an Action to copy the deeplink for the current note in the Search Notes list is the most reasonable thing, compared to a script command, etc.

As for what to do with deleted notes, I'll leave this to others as I have the questionable habit of never deleting notes.

StevenRCE0 commented 1 year ago

The script here uses AppleScript and sqlite3 to get the selected note URL with AppleScript -- shouldn't be too difficult to modify this to get the deeplink of any particular note. Still doesn't work for "On This Mac" notes, but it seems like those just don't support deeplinks at all.

Yep, I've seen the post. However, isn't it a subset of what we've got in the database?

SKaplanOfficial commented 1 year ago

Yes, I believe so, however it provides a way to get the UUIDs for the deleted notes currently obtained via AppleScript. That's for if you want to support deeplinks for deleted notes too without changing the AppleScript fetching approach.

StevenRCE0 commented 1 year ago

Yes, I believe so, however it provides a way to get the UUIDs for the deleted notes currently obtained via AppleScript. That's for if you want to support deeplinks for deleted notes too without changing the AppleScript fetching approach.

https://github.com/raycast/extensions/blob/9064cbca84b1cca1295b6efc566bec9f71efe98c/extensions/apple-notes/src/useSql.ts#L110

This query excludes the deleted on purpose. We can get the UUID of those without workaround.

dreasan commented 1 year ago
  • Only iCloud notes are shown in sqlite database(for example, "On My Mac" notes are absent in my tests), and we could get promising URLs for those ones.

I could find an On my Mac test note in the SQL lite database, specifically the ZICCLOUDSYNCINGOBJECT table.

My method:

  1. Created a new local note titled New local note.
  2. Used this Shortcut based on this thread to search for the local note.
  3. Used the graph viewer to navigate and view the note object.
  4. Copied the UUID from the URL inside the object: notes://showNote?identifier=UUID
  5. Queried with SELECT * FROM ZICCLOUDSYNCINGOBJECT WHERE ZIDENTIFIER = '<UUID>';

For me, this returned the note data for the On my Mac note. I am uncertain if it had to do with the fact that I created a fresh note. I normally do not use the local note account.

dreasan commented 1 year ago

I think an Action to copy the deeplink for the current note in the Search Notes list is the most reasonable thing, compared to a script command, etc.

I would prefer an Action too.

dreasan commented 1 year ago
  • With mobilenotes:// instead of notes://, we can make the URL work on iOS! I think that's also quite helpful.

Yes, I think both make sense. If I had to choose, though, I would go for notes://. Considering, Raycast is built for macOS. An option for mobile could help with use cases, where you reference the content mainly from your phone. These users would likely use mobilenotes:// most of the time. I think a second action won't produce much clutter (e.g., Copy Mobile Link), so it should probably be added.

A little sad that it's a different scheme for mobile vs. desktop. But okay, better than nothing.

StevenRCE0 commented 1 year ago

It rocks! The best approach is to fetch everything through db and ditch AppleScript fetching entirely. It'll not only solve this URL problem but also increase performance significantly.

I'm busy recently so no tests were done. Feel free to contribute!

dreasan commented 1 year ago

Just checked the recent changes. It's been working nicely so far. Great!

The only thing I noticed is that the ⌘+C shortcut is not working for me for the copying note URL action, whereas ⇧+⌘+C for the mobile note URL is working. With ⌘+C the clipboard just stays empty.

Triggering the action via the menu does work, though.

SKaplanOfficial commented 1 year ago

@dreasan Yep, seeing that on my end too. I thought it was working before, but I'm probably remembering wrong. In any case, I'll fix that soon when I work on #5968 and #5619.