Spotlight-enable Logseq: make opening .md files go to page in LogSeq

Just realised, that Spotlight on a Mac searches all of LogSeq’s markdown files.
This is great – because users who also use Apple Notes on the go/for input with stylus, can search their handwritten stuff in Apple Notes and their LogSeq notes in one query!

Only one step is missing: Right now one has to resort to opening the markdown file in a seperate editor. Logseq is not doing anything when being forced to open a .md file via the file manager/Finder/Explorer.

Guess it should not be too hard to make it open the correct page in Logseq, when double clicking a markdown file that is already sitting in the Logseq folder?

An .md file on your Mac might have any of a number of apps as its “owner”; that is, default app. So not sure how to telegraph that these .md files are special and should be opened in LogSeq, unlike this other pile of .md files you’d like opened in Obsidian or Ulysses or Typora…

That said, it does seem like you’re right - the code to receive that notification isn’t configured on the Mac app. So it’s not possible to set LogSeq as the default editor for .md files right now.

But, lastly, I see an issue here - what happens if you have graph A opened, and search pulls up a file in Graph B?

Would you think that proper behavior is to
…close out of graph A and open B so you can view the file? or
…import the document into the open graph?

-Robert

In a perfect world, I would expect Logseq to open up a new window.
Example: Start with Graph A open in Logseq. Then we double click some .md which is part of Graph B in Finder. A new Logseq window opens with Graph B open on the page corresponding to the clicked .md.

Edit: Additionally it could ask, if instead you want to import to Graph A/close the old window in a popup.

In theory it should be possible to write a simple sh script, in case someone is interested, this is how it would work:

  • the script would be assigned as default application to open .md files
  • it would of course take a .md file as input
  • it would check .logseq hidden folder to know which graphs are currently open
  • it would then check if the input .md file is in those graphs
  • it would check if Logseq is running
    • if yes, it would open the corresponding page using logseq:// protocol
    • if no, it would ask if Logseq must be started
      • if the user says yes, it would start Logseq, wait some seconds and then run the logseq:// call as above
      • if the user says no, it could open the file in another Markdown editor

No problem if the file/page does not belong to the currently open graph: Logseq will open a new window with the right graph and open the page there, I just tested it.

I can try to develop this for Linux but since there are some differences with MacOS and I have not a Mac, I can’t ensure it will be compatible.

2 Likes

I’d greatly appreciate, if you developed it for Linux!
Guess that would be my first opportunity to test ChatGPTs coding skills by pasting your code and saying “make this work on MacOS!” :smiley: … or just adapt manually.

Here you are, I hope it helps: