[英]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:您可以分两步执行此操作:
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.