obsidianmd / obsidian-importer

Obsidian Importer lets you import notes from other apps and file formats into your Obsidian vault.
https://help.obsidian.md/import
MIT License
754 stars 72 forks source link

Import from Apple Notes - $2,500 #15

Closed kepano closed 1 year ago

kepano commented 1 year ago

Please upvote this issue if you would like to see Apple Notes as an import format.

Bounty

See the Contribution guidelines for how to claim this bounty.

Bounty: $2,500 USD Timeframe: 21 days

Please only apply if you have taken time to explore the Importer codebase, as well as existing options such as Apple Notes Liberator and Apple Cloud Notes Parser. Provide detail about how you would approach solving it within the constraints of this Obsidian plugin.

Requirements

Current solutions

huyz commented 1 year ago

Make sure to check out https://github.com/threeplanetssoftware/apple_cloud_notes_parser

Star-Lord-XIII commented 1 year ago

I have been developing & maintaining Exporter for the past 7 years. Just started using Obsidian & loving it. If there are any special requirements needed for Obsidian that aren't being met with the current version of Exporter, please do let me know.

kepano commented 1 year ago

@Star-Lord-XIII have you investigated the new iOS17 format for internal links? It would be great to make sure those links are maintained via [[Link]] syntax once that feature becomes widely available.

Also can you confirm that Exporter's current Markdown export supports all attachment types (images, PDFs, etc), as well as advanced Markdown features like tables?

Star-Lord-XIII commented 1 year ago

I haven't investigated the new link format, will look into it.

Exporter's current Markdown supports almost all these formats for attachments & renders tables correctly in markdown. Images shared from iOS in HEIC & HEIF formats are converted to jpegs while exporting in markdown; they are present in the HTML exports as well but in original (HEIC/F formats). These image formats are not currently imported/supported correctly by most note taking apps, including Obsidian. One exception with attachments is scans made from iOS devices. A workaround for that is to convert them manually into PDFs and reattach them to the note, which should work since PDF attachments are supported. I haven't found a better solution for this one yet as Apple Notes APIs don't expose scans from existing endpoints.

ReblochonMasque commented 1 year ago

Your app worked wonderfully for me @Star-Lord-XIII - Many thanks!

kepano commented 1 year ago

A $2,500 bounty has been added to this project.

Star-Lord-XIII commented 1 year ago

MacOS 13.5 doesn't expose iOS 17 internal links via attachments or body content. So there is no way to access those yet as far as I have tested. Same goes for todo lists. All other requirements mentioned in bug -- images, attachments, tables and Obsidian-compatible markdown are already supported by Exporter.

kepano commented 1 year ago

@Star-Lord-XIII this issue is for adding support within the Importer plugin, without the need for a separate tool

Star-Lord-XIII commented 1 year ago

Acknowledged.

holtwick commented 1 year ago

I have been developing & maintaining Exporter for the past 7 years. Just started using Obsidian & loving it. If there are any special requirements needed for Obsidian that aren't being met with the current version of Exporter, please do let me know.

@Star-Lord-XIII Your tool is almost perfect and the best I found for exporting Apple Notes. There is one little thing, although an important one, that does not seem to work: export of links (see attached Screenshot of an export to Markdown). Other exporters experience the same issue, therefore I wonder if this is due to limitation of the source data.

20230912-081352-capture-holtwick@2x

winged-voices commented 1 year ago

@holtwick

@Star-Lord-XIII Your tool is almost perfect and the best I found for exporting Apple Notes. There is one little thing, although an important one, that does not seem to work: export of links (see attached Screenshot of an export to Markdown). Other exporters experience the same issue, therefore I wonder if this is due to limitation of the source data.

I can't get Apple Notes to send coherent links as any easy share (I'm sure there is a way, but it's above my coding experience; I came over here to see if someone had snagged this bounty) to ANY other format, even directly from the native "Share to..." on my iPhone or iPad, especially if they are or have ever shown up as rich links. That may be part of the issue. I can see that they're not rich links here, but if it's ever converted into the preview format and you had to hit backspace or x out, it may still need kid gloves.

(A HUGE pain when using Notes as a quick bookmarking system and then trying to send it to yourself on a product where you can't pull up iCloud. Most things print them as text only like the first highlighted one. Again, I'm sure there is a workaround but Notes is frankly terrible for link lists.)

mirnovov commented 1 year ago

I would like to apply for this if possible - this seems like a fun thing to complete.

I have developed the Obsidian Homepage plugin, which is the 30th most popular in the community plugin repository. Additionally, I used to use Apple Notes as my primary note-taking solution and still use it for a few small things (though I use Obsidian for anything substantial), so I'm well-acquainted with what users expect and to test the correctness of any solution that would be developed.

I have examined the Importer code and have already developed a basic proof-of concept AppleNotesImporter that takes the Apple Notes database and decodes the note files, and intend to complete it and create a full-featured solution if this is accepted.

FilipLaz commented 1 year ago

It would be nice to see requirement for tags for importer.

Star-Lord-XIII commented 1 year ago

I have been developing & maintaining Exporter for the past 7 years. Just started using Obsidian & loving it. If there are any special requirements needed for Obsidian that aren't being met with the current version of Exporter, please do let me know.

@Star-Lord-XIII Your tool is almost perfect and the best I found for exporting Apple Notes. There is one little thing, although an important one, that does not seem to work: export of links (see attached Screenshot of an export to Markdown). Other exporters experience the same issue, therefore I wonder if this is due to limitation of the source data.

20230912-081352-capture-holtwick@2x

Yeah, source is the cause of missing links and todo-list status. Unless the data is either present in the HTML body of the note or in the attachment list it cannot be exported by a sandboxed app which needs to follow the entitlement constraints to publish the app on AppStore. With links and todo lists I hope the Obsidian Importer will have an easier time since it will be outside AppStore and can have direct access to the Note's SQLite instance.

geekforbrains commented 1 year ago

I have been developing & maintaining Exporter for the past 7 years. Just started using Obsidian & loving it. If there are any special requirements needed for Obsidian that aren't being met with the current version of Exporter, please do let me know.

Huge fan of Exporter! 🙇‍♂️ Thanks for your work on that.

neo773 commented 1 year ago

Hi there, I'd like to apply for this.

My approach doesn't ask users to grant full disk access, which I think is a bit invasive. The main point of a built-in importer is to make things easier for non-tech people, so this might put them off a bit.

It's based on Apple JXA (JavaScript for Automation) and written in TypeScript. This PR shows how my approach works.

If this gets picked, I can work on it more to fix and iron out the bugs.

Thank you.

pyeguy commented 1 year ago

would be great to support export as pdf for handwritten notes!

mirnovov commented 1 year ago

@neo773 The way I see it, your solution has a different set of trade-offs but I wouldn't explicitly call it better.

Again, I see trade-offs inherent to both approaches, and I trust Obsidian's developers to make the right judgement. While the bounty is nice I think they should go with whatever is the most technically sound solution, not the one that happens to benefit me the most. Given that Apple pretty strictly sandboxes its apps I don't think there's going to be a solution without some sacrifices but if someone comes up with one I'd be impressed.

neo773 commented 1 year ago

@mirnovov

Thanks for insights appreciate it!

it tells me "Notes account not found" despite my account being extant and having plenty of notes.

My PR was WIP so the account not showing up bug can be fixed, the current implementation is hardcoded that's why you can't see your folder.

Not sure about having to prompt to export then select which notes to import,

It's also doable, see 1st point.

It wouldn't surprise me if the HTML export in Sonoma just strips them;

I haven't upgraded my mac yet will test it soon.

Your solution massively increases the Importer JS output size to 21.3 MB

Seeing 3.4 MB on my end when building for production, it's the 2md library that's caused it to balloon This was quickly put together so the lib can be swapped with the builtin parser.

Also it was not my intention to go around Obsidian bounty rules (with the PR), I've been doing open source bounties listed on Algora.io which works a bit differently. So, I'm sorry about that.

thebrandantyler commented 1 year ago

AppleScripts x Osascript

MacBook Air - 1

Pros

  1. Reliably parse basic Apple Note files as a single file or in bulk using the Note Suite Library.
  2. Supports HTML content retrieval.
  3. Supports plain text retrieval and attachment retrieval.
  4. Can retrieve full links.
  5. I would love to work with neo773 on this as neo seems to have quite a decent solution already prepared. I am currently just running AppleScript code in Node via a string and the osascript command. Most data imports correctly.

Cons

  1. Cannot retrieve internal embedded links with custom text.
  2. Cannot retrieve IOS17 internal links at all.

    Requirements

Obsidian x Apple Shortcuts

MacBook Air - 2

Pros

  1. Does not need to use Obsidian Importer.

  2. End users will have free range to manipulate the shortcut according to their needs.

  3. Can import/export single Apple Notes or multiple Apple Notes.

  4. Obsidian users can create custom shortcut links and custom params to fire their shortcut using this format: shortcuts://run-shortcut?name=[name]&input=[input]&text=[text] .

  5. Is a true mobile and macOS solution! - A solution I am invested in.

    Cons

  6. AFAIK you can't grab videos/markup in bulk on mobile unless the user individually selects the video/markup and shares it. It does however, leave the file name which can then be parsed and found when the user logs into a macOS system.

  7. Mobile users will have to install the shortcuts app.

  8. Is an external tool outside of Obsidian.

    Requirements

Internal IOS17 links with the same name as the link are currently not supported in macOS 13 or even when copying text to the clipboard. The potential solution here would be to match the exact text with existing note names and parse accordingly. Even then, the user would need to manually approve these changes as some title names may appear as regular text in subsequent documents.

NoteStore x SQLite

MacBook Air - 3

Pros

  1. Easy way to access all Apple Note data all at once.

  2. Great for if an Obsidian user keeps NoteStore.sqlite files in a external hard drive and needs to import them.

  3. Great for if an Obsidian user needs to recover NoteStore.sqlite data.

    Cons

  4. You will need to have an intermediate to advanced level of SQL knowledge to understand, navigate and integrate this logic.

  5. Apple can at any time choose to change their note storage structure as they have many times in the past.

  6. This is my least researched and experimented solution. I have reliably retrieved basic Apple Note data using this method. However, I would happily work with or pass off this integration to mirnovov as mirnovov seems to know more about this.

    Requirements

Useful Mentions

  1. You can create a clipboard listener to synchronously generate obsidian notes.
  2. You can use a UI parser to automatically navigate the UI and gather note data.
  3. You can use Automator Record Workflow to automatically navigate the UI and gather note data.
  4. You can create a PDF parser for users to upload exported Apple Note PDFs.
  5. You can get crazy and parse iCloud blobs received from the server. Probably against the rules.

    Conclusion

Ideally, all of the solutions should be integrated for an inclusive solution. In my professional opinion, I would integrate in this order:

  1. Apple Shortcuts - Obsidian Apple Shortcut Tool - User friendly, non-invasive, faster to set up, easily accessible, requires 0 new npm packages & 0 new installer updates for Obsidian users.
  2. AppleScript x Osascript - Great way to pull legacy note & attachment data with a minimal footprint. Users who wish to have embedded internal links transferred will need to use the Obsidian Apple Shortcut Tool.
  3. NoteStore x SQLite - Great solution for users who store their note data on external drives, users who may have lost data or advanced users who want to just have more overall control of their notes DB.

    Why Hire Me?

Also, I have a ton of Apple Notes and I need them properly imported lol...

I hope at least some of this information was useful to any current or future developers looking at this.

Let's build something great!

tgrosinger commented 1 year ago

@mirnovov, a couple of questions we'd like to verify about your approach:

  1. Can you please elaborate on what you mean by a binding library for sqlite? What library are you using, and will it work on both M-chips and Intel Macs?
  2. What does granting the Full Disk Access permission look like to the user? Does this happen automatically the first time they use the plugin? Are there any changes that need to be made outside of this importer to make it so that Obsidian and this plugin can request that permission from the OS? What if the user revokes the permission later, will it prompt again next time they import?

Thank you

mirnovov commented 1 year ago
  1. I use sqlite-tag-spawned. Since this just calls the SQLite executable bundled with macOS, it should be compatible across architectures.
  2. As I stated above, macOS doesn't have a native permissions prompt for this. However, you can open the settings pane for it with the URL x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles (you can test it yourself by using the open command in the shell). There would be an Obsidian prompt beforehand that would explain to the user what to do.
kepano commented 1 year ago

@mirnovov you have been assigned the bounty! Please submit your initial PR by end of day (GMT) on October 16th, 2023.

Join the #plugin-dev/importer channel if you have any questions: https://discord.gg/obsidianmd


Thank you @neo773 and @BrandanTD for your very thoughtful submissions. This is a situation where all of the options have significant tradeoffs. We have decided to pursue the SQLite approach despite its downsides. We may ultimately need to explore the AppleScript approach if we hit a roadblock with SQLite, but we'll cross that bridge when we come to it.

thebrandantyler commented 1 year ago

Congrats @mirnovov on the bounty acquisition! Can't wait to see what you come up with!

@kepano Happy to help!

I do however, humbly request that you consider concurrent approaches or future solutions to this project. In my research, I have come to the conclusion that at minimum the SQLite and Apple Shortcut approach must be implemented to complete all of the project requirements.

SQLite Approach

The SQLite approach will be needed for past, current or future datastore retrieval no matter what. I am still unsure if it will be able to retrieve IOS 17 internal links, but I am sure @mirnovov will figure that out. Although, I do know it is not an IOS solution.

Apple Shortcuts Approach

I have successfully built an Apple Shortcut as a standalone to extract, decrypt and export Apple Note files. I have also created a simple export shortcut to export Apple Note Files and attachments to a zip that can then be read by the Obsidian importer (see demo below.)

In my research, I have not been able to find out how to communicate with internal Apple Note functions on IOS without the use of a third party vendor, Apple Shortcuts or exposing native modules to communicate between Obsidian and Apple Notes.

These solutions should meet all of the listed requirements without within the constraints of this Obsidian plugin.

Apple Shortcuts Solution MacOS Demo

MacOS Demo

Apple Shortcuts Solution IOS Demo

IOS Demo

Requirements

Issues

To Do

Closing Statement

I do not mean for this to take away from @mirnovov's bounty as mirnovov has earned it. I would like to see the SQLite solution and the Apple Shortcut solution implemented.

I request, given this new found information, that this solution will be separate from this bounty. I would be happy to sit down and discuss further details at your convenience.

I understand if you do not want to follow through with this approach. I will continue to build it regardless as I still personally need the solution and I am close to wrapping this up.

kepano commented 1 year ago

@BrandanTD thanks — please open Apple Notes Shortcut as a separate issue so we can keep this issue focused on the SQLite approach. Shortcuts could be an alternate path for some users, but we don't see this as the primary solution for Importer. We also accept issues/PRs to the Help repo if you want to document this solution.

mirnovov commented 1 year ago

I have upgraded to macOS Sonoma and confirm that the internal links can be retrieved (quite easily in fact, since it builds on existing aspects of the data format). Haven't really done too much yet as I have been quite busy lately, but I am confident I can meet the deadline barring exceptional mitigating circumstances.

peb7268 commented 3 months ago

If I set this importer to run on a cron daily, will it create a ton of duplicates or will it just import new notes?

I would like to use apple notes for daily quick notes and obsidian as long term curated storage.

kepano commented 3 months ago

It will create duplicates, see #142

peb7268 commented 3 months ago

So given that this is an open issue, Is this on the roadmap to implement?

Thanks, Paul

On Jul 15, 2024, at 2:50 PM, Steph Ango @.***> wrote:

It will create duplicates, see #142 https://github.com/obsidianmd/obsidian-importer/issues/142 — Reply to this email directly, view it on GitHub https://github.com/obsidianmd/obsidian-importer/issues/15#issuecomment-2229408070, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJE4ZWGFVFMSTB2C2UX6QLZMQY23AVCNFSM6AAAAABK5GPFLGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRZGQYDQMBXGA. You are receiving this because you commented.