Network file path to clipboard for Windows/Mac environment.

Hello, sorry for the long read but I´ll very much appreciate any help on this.

I´ve been searching for this online for quite some time and to some extent I´ve been finding things but never found exactly what I was looking for, and I am sure I am not the only one with this problem. Please note I am very new to Applescript.

We just deployed around 30 macs for a department in my workplace and we are no longer a Windows only environment.

One of the main difficulties I´ve found no solution to during this implementation is network file path sharing between a Mac to a Windows user i.e \\servername\folder\file.ext.

We managed to find a script to open file paths from Windows to Mac, it installs as a Service which it mounts the drive using smb and also inverts the \.

But Mac to Windows, everything I´ve found online, from contextual menus, to services, to automator, to scripts is to copy the file to the clipboard with the same result as if you drag the file to the terminal which results in /Volumes/folder/file.ext but of course Windows cannot read this path.

I´ve also tried to tell the script to replace the /Volume for \\servername but if the volume is mounted deep into subfolders then the link is broken as not the whole path is displayed.

The only place I´ve noticed that you can find this exact information in Mavericks is when you hit Get Info, it displays Kind, Size, etc as well as Where: /Volumes/folder and also the field Server: smb://servername/folder/file.ext. Is there a way to retrieve this in Applescript so that we can just delete the smb: part and change the / to \ and finally copy it into the clipboard to send the link via email between departments?

Thanks for the help.

iMac, OS X Mavericks (10.9.4)

Posted on Sep 1, 2014 6:29 AM

Reply
3 replies

Sep 1, 2014 7:44 AM in response to esnowleopard

This may not solve the deeply nested folders problem. I couldn’t find a way to get that server field info.

I’m not sure if this is the best way, and I haven’t exhaustively tested it, but this seems to work:

Create an Automator Service that receives selected files or folders in Finder.

Add a Run Applescript action from the Utilities Library.

Set the script to this:

on run {input, parameters}

  set filePath to POSIX path of input
  set olddelims to AppleScript's text item delimiters
  set AppleScript's text item delimiters to "/"
  set pathParts to text items of filePath
  set startPart to 2
  if pathParts contains "Volumes" then
  set startPart to 3
  end if
  set pathParts to items startPart thru (count of items in pathParts) of pathParts
  set AppleScript's text item delimiters to "\\"
  set output to "\\\\" & (pathParts as text)
  return output
  set AppleScript's text item delimiters to olddelims
end run


Add a Copy to Clipboard action (also in Utilities).

Save this service with a short name like Copy Path.

When you ctrl-click a file, you can select the service from the Services menu. It will copy the path formatted as \\server\share\file

You could also add a shortcut for the Service in the Keyboard Shortcuts pane of the Keyboard system prefs.


If you want to paste both paths, use this script:

on run {input, parameters}


set filePath to POSIX path of input

set olddelims to AppleScript'stext item delimiters

set AppleScript'stext item delimiters to "/"

set pathParts to text items of filePath

set startPart to 2

if pathParts contains "Volumes" then

set startPart to 3

end if

set pathParts to itemsstartPart thru (count of items in pathParts) of pathParts

set MacPath to "Mac: smb://" & (pathParts as text)

set AppleScript'stext item delimiters to "\\"

set WinPath to "Win: \\\\" & (pathParts as text)

return WinPath & return & MacPath

set AppleScript'stext item delimiters to olddelims

endrun

Sep 1, 2014 8:45 AM in response to Barney-15E

Thanks very much for your reply Barney-15E.

I´ve managed to come this far using a service which does the same as yours that replaces the /Volume for \\Myservername\folder, but we´ve got different drives in different offices so I need to create the copy path service for each drive.

The solution I´ve found so far to open links received from Windows users in the form of \\servername\folder\file.ext is to mount directly into that point, thus doing the same thing as Connect to Server, which creates another mount that when using this copy path service from within this mount will add a -# (# depends on how many times the same drive has been mounted) i.e \\servername\folder-1\file.ext, but also misses folders above that mount point. I think this is also part of the problem I am having. Is there a way to tell Finder to open the linked file from the already mounted drive, instead of mounting a new one?

Sep 1, 2014 9:18 AM in response to esnowleopard

I would think you could look at the share name and see if it exists in Volumes, then if it does, append /Volumes/ to the file path and then tell Finder to open that path.


Since there isn’t a way to get the Server info that populates Get Info, I would think you might have to create a mapping dictionary that links share names to servers. You could then lookup the servers to append to the path.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Network file path to clipboard for Windows/Mac environment.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.