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.
