New here, but I'm having difficulty putting together an AppleScript that will basically take an SMB link and turn it into a UNC link before I send it over to a couple of Win10 clients.

All same network, we're all using a SNS NAS and it's for Adobe Premiere links. We can do this all manually, but the editors don't have time/patience to convert each link. We're looking for an automated script that we could integrate as a service that will convert selected text.

I found the article below, but it's the reverse to what we're looking for. I tried reversing all of the functions in it but wasn't able to get it to run properly.


It'd also be awesome if the 'service' that is created simple copies the entry into the clipboard so that the end-user can paste it into a couple of different things like email and Slack messenger.

Hopefully someone can help or steer me in the right direction. I've been scouring Google for this for about a week.

EDIT** Examples below

Old path 'smb://server/folder'

New path '\\server\folder'

  • I deleted my original answer after some comments by klanomath because at the time it was late and needed to sleep. I've added a caveat, the note at the top of my answer, and undeleted it. Hopefully as an example it covers your needs however if you need more than that, then undated your question accordingly and if you need additional help with the coding I'll see what I can do for you. Apr 19, 2017 at 16:48

2 Answers 2


maybe a little late to the party, but we use a 3rd party app for this at work


works pretty well, especially that you can rightclick any file on an UNC Drive and copy the pathname to get the windows result


NOTE: This answer is intended only as an example when the SMB Path, aside from the colon, slashes and backslashes and without spaces, only contains alphanumeric characters in the name! If you need to account for anything else, i.e. read the comments to this answer, you'll need to modify the code according to your needs. That said, in all of my years as a Network Systems Administrator and Network Systems Engineer I never created shares containing spaces or other then the need for colons, slashes, backslashes and alphanumeric characters and therefore this simple example is all that I'd need to translate any, e.g. smb://server/folder to \\server\folder, SMB Path I ever used to a UNC Path. YMMV!

In Automator, create a new Service workflow, then add a Run AppleScript action to it while replacing the default AppleScript code with the code below:

on searchReplace(theText, SearchString, ReplaceString)
    set OldDelims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to SearchString
    set newText to text items of theText
    set AppleScript's text item delimiters to ReplaceString
    set newText to newText as text
    set AppleScript's text item delimiters to OldDelims
    return newText
end searchReplace

on run {input, parameters}
    set selectedText to item 1 of input as string
    set convertedText to searchReplace(selectedText, "smb://", "\\\\")
    set convertedText to searchReplace(convertedText, "/", "\\")
    set the clipboard to convertedText as string
    return convertedText
end run

Then save the Service as: Convert SMB Path to UNC Path

Now Convert SMB Path to UNC Path will appear on the Services menu or Services context menu when text is selected and when the Service is used, the UNC Path is placed on the Clipboard. (This of course assumes the selected text was actually an SMB Path, otherwise what's placed there is just whatever text was selected when the Service was run which will include any substitutions made.)

Example SMB Path smb://server/folder will be converted to UNC Path \\server\folder and placed on the Clipboard.

Note: Note the settings of the Service in the image below. The Output replaces selected text checkbox is unchecked. You may check it, if that's what you want, however, if the selected text is not actually replaceable then the Service will not appear on the Services menu or Services context menu.

Convert SMB Path to UNC Path Automator Service

  • What happens when the SMB path contains spaces or \ escaped spaces?
    – klanomath
    Apr 19, 2017 at 1:50
  • @klanomath, Hadn't though about that! I guess the first substitution could be set convertedText to searchReplace(selectedText, "\\", "") which will remove any backslashes and thus I assume handle an escaped space. Can UNC Paths have spaces? If yes, should a UNC Path having space be quoted? Apr 19, 2017 at 2:21
  • AFAIK UNC paths containing spaces should be quoted in Windows. Escaping them or a %20 probably won't work
    – klanomath
    Apr 19, 2017 at 2:25
  • @klanomath, So then, I should add the suggested code of my first comment and then have the convertedText, which will be the UNC Path placed on the Clipboard and have it quoted whether of not it has spaces would still be okay quoted? I'm not able to test at the moment and why I'm asking for your input. Thanks. Apr 19, 2017 at 2:41
  • Hmm it's OK but ugly. I also recommend to post a warning when the POSIX path contains <>|?*".
    – klanomath
    Apr 19, 2017 at 2:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .