Nodejs使用默认预览打开本地文件
我正在尝试使用Electron创建一个桌面应用,该应用程序包含一个函数,其中用户可以打开保存在本地存储中的所需文件。正弦我正在使用MacOS,我想使用nodejs能够在默认预览软件中打开文件(例如PDF DOC)。有什么办法做到这一点吗?
先感谢您。
I am trying to create a desktop app using electron which includes a function where a user can open a desired file saved in the local storage. Sine I am using MacOS, I want to use nodejs to be able to open the file (e.g. PDF doc) in the default preview software. is there any way to do this?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种便携的方法是利用电子的 shell> shell api,特别是<<< rel =“ nofollow noreferrer”> shell.openpath.opentath
a href =“ https://www.electronjs.org/docs/latest/latest/api/shell#shellpopenpath ” 渲染器过程,也可以用来打开查找器中的文件夹。
A portable way is to make use of the Electron's shell API, specifically the shell.openPath method:
It is available both in the main process and in the renderer process, and it can also be used to open a folder in the Finder.
方法
如果有人想知道我找到了一种使用此二手命令壳(终端)打开它的 。如果还有其他更好的方法可以做到这一点,请告诉我们!
if anyone is wondering I found a way of using
this used command shell (terminal) to open it. If there is any other better way to do it please let us know!