SingleFile icon indicating copy to clipboard operation
SingleFile copied to clipboard

Integrate SingleFile with the Safari Share Extension framework

Open gildas-lormeau opened this issue 1 year ago • 3 comments

The goal would be to include a “Save page to Notes” and “Save selection to Notes” in the list of suggestions.

gildas-lormeau avatar Feb 04 '24 13:02 gildas-lormeau

I just posted an article for my publication, Apple Dispatch, about integrating SingleFile, Apple Notes and Safari that is relevant to this suggested feature request and also how to harness the power of SingleFile in general.

The way that I'm sharing items now is by Right-clicking the downloaded HTML file, selecting Share…, and then choosing Notes. It would be great to have the tighter integration built directly into the Safari Share Sheet.

Thanks for your continued efforts on such an amazing tool!

appledispatch avatar Feb 14 '24 17:02 appledispatch

Thank you very much for the article. I did a quick test in Safari and it looks promising. The good news is that it supports the navigator.share() API.

FYI, here is the test I did:

  1. Open https://www.example.com in Safari
  2. Open the JavaScript console (via the menu Develop > Show JavaScript Console)
  3. Paste the code below in the console and press Enter
document.onclick = () => navigator.share({ files: [new File([ document.documentElement.outerHTML ], "example.html")]})
  1. Click anywhere on the page
  2. A popup should allow you to add the page in Notes

I will do a more advanced integration test in SingleFile, I'll keep you informed ;)

gildas-lormeau avatar Feb 16 '24 00:02 gildas-lormeau

That is absolutely fantastic! I just ran the code you posted and it works perfectly! Thanks for sharing it.

I noticed if I click away from the share sheet, without sharing to Notes, I get these errors in the console: (Unhandled Promise Rejection: InvalidStateError: share() is already in progress) and this one: (Unhandled Promise Rejection: AbortError: Abort due to cancellation of share.) Maybe this is the intended behavior?

I put the word out about my article highlighting SingleFile over at the excellent /MacApps subreddit and they are really digging it there. It’s turning on a lot of people (≈ 3.9k currently) to your wonderful extension in the Apple community.

Yes indeed, please keep me in the loop as things progress. I will be posting about this @Apple Dispatch for my Apple Notes series once this feature becomes a reality.

Truly exciting developments!

appledispatch avatar Feb 16 '24 19:02 appledispatch

It's implemented. I added a new option share page in the Destination section. When checked, a banner with a Share page... button will appear at the top of the page when you save it. By clicking on this button, you will be able to share the saved page on Notes, see the screenshot below. Unfortunately, this button requires an extra click, but I have no choice from a technical point of view.

The new option will be available in the next version.

image

gildas-lormeau avatar Feb 18 '24 21:02 gildas-lormeau

Thanks so much for your excellent work on this new feature! I love to see SingleFile getting even tighter integration with Safari and Notes.

Can't wait to see this drop on the App Store.

appledispatch avatar Feb 19 '24 02:02 appledispatch

The new version (1.2.0) is available for download on the App store.

gildas-lormeau avatar Feb 19 '24 21:02 gildas-lormeau

This is absolutely killer! Is there a way for this new implementation to also work for Save selection to Notes?

appledispatch avatar Feb 20 '24 01:02 appledispatch

Actually, it should also work for selection if you use the context menu and select 'Save selection' instead of clicking on SingleFile button.

gildas-lormeau avatar Feb 20 '24 12:02 gildas-lormeau

That's great! Is there a way for the 'Share page…' button to change to 'Share selection…' when choosing that option from the context menu?

appledispatch avatar Feb 20 '24 17:02 appledispatch

Thank you for the suggestion, it is fixed. The fix will be available in the next version.

gildas-lormeau avatar Feb 20 '24 21:02 gildas-lormeau

Any time. Well done!

appledispatch avatar Feb 21 '24 01:02 appledispatch

Is there a way to get macOS Spotlight to index the HTML files saved by SingleFile? It seems that files saved to Apple Notes can only be searched by title and not by the text contained within each HTML document.

appledispatch avatar Mar 01 '24 23:03 appledispatch

I don't think it's possible. It looks like it's a "bug" in Notes, see https://discussions.apple.com/thread/251960240?answerId=253757819022.

However, you can search for attached pages with the Finder in ~/Library/Group Containers/group.com.apple.notes/Accounts.

gildas-lormeau avatar Mar 02 '24 00:03 gildas-lormeau

You're definitely on to something with that Apple Discussion thread. I was able to find out that Spotlight will index and search text content within Safari webarchives, but Notes cannot do the same. It looks like Apple did not implement that part of the Spotlight Index API in Notes.

So, it seems pretty clear why Notes cannot search SingleFile archives, but I'm still not sure why Spotlight can't search them. Maybe, Apple only allows the API to work on its own HTML archive format?

appledispatch avatar Mar 02 '24 04:03 appledispatch