简体   繁体   中英

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

We can accesss the remote files via SMB protocol

Finder Menu > Go > Connect to server.

ex: 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. Now if i need to open the master.tif file i need to double click and open it. But for the connection i entered address of the file.

Iam trying to achieve same functionality with safari extension .

NSWorkspace.

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

Result: Same :(

When tried with 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? 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
  2. Open the file within that mount mount.
  3. Unmount the SMB share when you're done with it.

I couldn't find a way to do #1 in a predictable manner. 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.

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) .

You can try using the Process API to call mount_smbfs (which is just a wrapper around 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.

From there, you can open the file as normal:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM