Converting file links formated for Windows to Mac

I am one of a grand total of two Mac users in a 700 person firm, so I receive multiple emails a day with file links that are created in Outlook and formatted using Windows’ file scheme of file:\\\server\path (why there are five backslashes, I have no idea). Does anyone have an Automator Service or a Keyboard Maestro macro (or whatever) that would take that input and spit out a link that works on macOS? If not that, maybe some ideas on how I might go about writing my own? It seems like it is just text string manipulation that I should be able to do as an Automator Service so when I right-click a link and select the service from the menu, that link actually works.

This looks apropos:

I thought I was the only one.

I have an AppleScript/Automator service that I’ve worked on sporadically for months that opens the file or folder most of the time. I’ll try to remember to post it when I’m back in the office tomorrow.

There’s a more extensive script here:

I’m looking at the script I wrote, and I think @JohnAtl’s two links are probably more helpful to you than mine would be. (The first of those two posts is where I got the foundation of the script I ended up writing.) Mine is kind of a highly customized version of what you’ll find in those two posts, which is probably what yours will end up being.

1 Like

Thanks! I’ll check those out.

It took a little doing, but I managed to create a Keyboard Maestro macro to take text from the clipboard, convert to a Mac-style path, and open the resulting file or folder. Here’s the code for it.

Assumptions:

  • I only need to deal with a single server name, so it’s hard coded in the first replacement line (look for file://///SERVERNAME/. If you need the ability to determine server name on the fly, you’ll need to modify it even further.
  • I already have the shared volume mounted on my Mac, so I’m just replacing the beginning of the string with /volumes/. If you don’t have it moun ted with the same name, you’ll have to edit more.

Slap this into an Execute Applescript action, edit the server name to whatever you use, and assign a hot-key.

--references:
--https://stackoverflow.com/questions/5418450/edit-clipboard-content-with-applescript-in-os-x
--https://stackoverflow.com/questions/11261516/applescript-open-a-folder-in-finder

on replacement of oldDelim by newDelim for sourceString
	set oldTIDs to text item delimiters of AppleScript
	set text item delimiters of AppleScript to oldDelim
	set strtoks to text items of sourceString
	set text item delimiters of AppleScript to newDelim
	set joinedString to strtoks as string
	set text item delimiters of AppleScript to oldTIDs
	joinedString
end replacement

on run
	--get input from the clipboard
	set mylocation to the clipboard
	
	--do the replacements
	set mylocation to (replacement of "file://///SERVERNAME/" by "/volumes/" for the result)
	set mylocation to (replacement of "%20" by " " for the result)
	
	--open the file/folder
	tell application "Finder" to open (mylocation as POSIX file)
	
	--display in the result window
	set mylocation to mylocation
end run
2 Likes