简体   繁体   English

是否可以在没有手动交互的情况下在本机应用程序中启动远程文件

[英]Is it possible to launch remote file in native application without manual interaction

We can accesss the remote files via SMB protocol我们可以通过SMB协议访问远程文件

Finder Menu > Go > Connect to server. Finder 菜单 > 前往 > 连接到服务器。

ex: smb:///cifsshare/master.tif"例如:smb:///cifsshare/master.tif”

But when we push the command, we only end up to opening the enclosing directory and not to the tif file.但是当我们推送命令时,我们最终只会打开封闭目录而不是 tif 文件。 Now if i need to open the master.tif file i need to double click and open it.现在,如果我需要打开 master.tif 文件,我需要双击并打开它。 But for the connection i entered address of the file.但是对于连接,我输入了文件的地址。

Iam trying to achieve same functionality with safari extension .我正在尝试使用safari 扩展实现相同的功能。

NSWorkspace. NSWorkspace。

if let url = URL(string: path) {
    if NSWorkspace.shared.open(url) {
       print("Url is opened")
    }
}

Result: Same :(结果:相同:(

When tried with Process()尝试使用 Process() 时

//1
let toolPath = "/usr/bin/open"
let arguments = [pathUrl.absoluteString]
     
//2
let task = Process()
task.launchPath = toolPath
task.arguments = arguments
     
task.launch()
task.waitUntilExit()

Result: Not Working :(结果:不工作:(

Is it even possible in macos?在 macos 中甚至有可能吗? Any clue how to achieve this, is highly appreciated.任何如何实现这一目标的线索,都受到高度赞赏。

You can do this as a two step process:您可以分两步执行此操作:

  1. Mount the SMB share to a local mount point将 SMB 共享挂载到本地挂载点
  2. Open the file within that mount mount.打开该安装挂载中的文件。
  3. Unmount the SMB share when you're done with it.完成后卸载 SMB 共享。

I couldn't find a way to do #1 in a predictable manner.我找不到以可预测的方式做 #1 的方法。 Ie, if something was already mounted at /Volumes/cifsshare , then opening smb:///cifsshare would automatically mount it to a new folder ( /Volumes/cifsshare (1) , if I recall correctly), without giving you feedback as to where exactly it ended up.即,如果某些内容已经安装在/Volumes/cifsshare ,那么打开smb:///cifsshare会自动将它安装到一个新文件夹( /Volumes/cifsshare (1) ,如果我/Volumes/cifsshare (1)话),而不会给你反馈它到底在哪里结束。

At a glance, it looks like the APIs that Finder uses to mount SMB reside within private frameworks , so there doesn't to be a nice easy API like SMB.mount(smbURL, to: mountPoint) .乍一看,Finder 用于挂载 SMB 的 API 似乎位于私有框架中,因此没有像SMB.mount(smbURL, to: mountPoint)这样的简单易用的 API。

You can try using the Process API to call mount_smbfs (which is just a wrapper around mount -t smbfs ).您可以尝试使用 Process API 来调用mount_smbfs (它只是mount -t smbfs的包装器)。 You can use it to mount your SMB share to a mount point of your own choosing, like /Volumes/MyAppSMBShare or whatever.您可以使用它将 SMB 共享挂载到您自己选择的挂载点,例如/Volumes/MyAppSMBShare或其他任何内容。

From there, you can open the file as normal:从那里,您可以正常打开文件:

NSWorkspace.shared.open(URL(fileURLFromPath: "/Volumes/MyAppSMBShare/master.tif))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 本机浏览器和android应用程序之间是否可能相互作用? - is it possible and interaction between native browser and android application? 使用本机文件系统 API 将文件保存到特定位置而无需用户交互? - Using Native File System API to save file to a specific location without user interaction? 以HTML 5或Javascript启动Native iPhone Maps应用程序 - Launch Native iPhone Maps Application in HTML 5 or Javascript 在手册页上启动 Puppeteer - Launch Puppeteer on a manual Page 是否有可能重定向用户启动扫描程序应用程序? - Is it possible redirect user to launch scanner application? 是否可以使用HTML / Javascript按名称启动应用程序? - Is it possible to launch application by name with HTML/Javascript? JavaScript - 两个用户代理是否可以在没有服务器交互的情况下进行通信? - JavaScript - Is it possible for two user-agents to communicate without server interaction? 是否可以在没有任何交互的情况下拍照? (Android Studio、CameraX) - Is it possible to take a picture without any interaction? (Android Studio, CameraX) 在JavaScript中,是否可以通过编程方式启动文件浏览器对话框? - In JavaScript is it possible to launch a file browser dialog programmatically? 如何在反应原生应用程序中检测应用程序首次启动? - How to detect application first launch in react native app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM