Is there anyone who has developed a plugin that directly calls the Mac’s built-in “Preview” software to read PDF files in ob?

I think the Mac’s built-in “Preview” is very useful. It can extract text from some PDF files, saving the work of OCR. I was wondering if it’s possible to design a plugin based on this feature of Mac, which can call this “Preview” on ob, similar to booknote, replacing the reader with the Mac’s built-in one. This way, I don’t have to use OCR when reading some books. I can just draw on it and copy and paste, which is very convenient.

For this, I asked about the feasibility of developing this plugin with ChatGPT. I am a beginner and I don’t understand it. Can a professional take a look?

I ask ChatGPT:

Assuming you are now an Obsidian expert, I need to write an Obsidian plugin that can call the Mac’s built-in “Preview” software to implement reading function in Obsidian. Please help me see if this is feasible.

ChatGPT’s reply is as follows:

In theory, it is feasible to implement this plugin. Obsidian is developed based on Electron, and the Preview application is a locally running application on macOS. Therefore, shell commands can be invoked by calling macOS to open the Preview application and load the document.

Specifically, the child_process module in Node.js can be used to call shell commands to start the Preview application and load the document into the preview. The code example is as follows:

const { exec } = require('child_process')

function openPreview(path) {
  const command = `open -a Preview.app '${path}'`
  exec(command, (err) => {
    if (err) {
      console.error(err.message)
    }
  })
}

In the plugin, specific shortcuts or commands in Obsidian can be monitored to obtain the path information of the selected document in Obsidian, and pass it as the corresponding path parameter to the openPreview() function. Then, the function will use the document path as a parameter in the shell command and call the open command to open the Preview application and automatically load the document.

It’s worth noting that this implementation mainly applies to macOS systems, as the default document viewer may not be the Preview application on other systems such as Windows or Linux.

Additionally, it’s important to ensure the security and compatibility of file paths and make different path handling for different systems.

Please take a look at this, thank you.:pray:

This code just opens the file in preview, the same as opening the file via the file explorer. The current pdf embed is pretty good, and I’m 90% sure you wouldn’t be able to embed a version of preview in Obsidian itself.