Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

convert pc file path to Mac and vice versa

Does anyone have a script for converting a file's path from OSX to Windows (by dropping it on an Automator application) and one for converting a Windows file path to OSX?


If not, could anyone explain to me how to do it?


Thanks.

Mac Pro Duo 2.33 and MbP 17" (work), Mac OS X (10.5.6), Final Cut Pro 6.0.5

Posted on Dec 4, 2013 12:41 AM

Reply
Question marked as Best reply

Posted on Mar 12, 2017 2:21 PM

Got a wild hair to solve this problem since it's been bugging me… first, I'll recap, then provide a solution +:

PROBLEM

From a Mac, I want to copy a file path on a network share into an email so that its clickable by poor Windows recipients. Currently, I copy/paste the path, e.g.:

smb://servername/MLS/Timbers/IrrefutableProofTimbersAreBestTeamInMLS.pdf

into an email, then manually convert it to a Windows path:

\\servername\MLS\Timbers\IrrefutableProofTimbersAreBestTeamInMLS.pdf


But that’s a stupid thing to do over and over, so I found some examples online (this forum and others) and hacked it until I got it to work a few ways (see below).


A related problem is when Windows users send me a file path and I want to quickly access it. Currently, I manually navigate to it by translating the path in my little head, which hurts. So, I reversed the hack above and added a call to open the folder to the file.

SOLUTION

In Mac OS Automator I created three Apple scripts that run as a service. This enables me to select a path, right-click and choose the appropriate service from the “Services…” menu, which I named:

“Convert Windows to Mac path and open it”

“Convert Windows to Mac path”

“Convert Mac to Windows path”

User uploaded file

DETAILS

Script: “Convert Windows to Mac path and open it”


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 myClip to the input

set mytext to searchReplace(myClip, "<", "")

set mytext to searchReplace(mytext, ">.", "")

set mytext to searchReplace(mytext, ">", "")

set findIt to "\\"

set replaceIt to "/"

set mylocation to searchReplace(mytext, findIt, replaceIt)

set mylocation to "smb:" & mylocation

tell application "Finder"

open location mylocation

end tell

return input

end run


-- Thanks to: http://apple.stackexchange.com/questions/144916/how-to-change-filepath-structure -using-automator-windows-to-mac --

Script: “Convert Windows to Mac path”

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 myClip to the input

set mytext to searchReplace(myClip, "<", "")

set mytext to searchReplace(mytext, ">.", "")

set mytext to searchReplace(mytext, ">", "")

set findIt to "\\"

set replaceIt to "/"

set mylocation to searchReplace(mytext, findIt, replaceIt)

set mylocation to "smb:" & mylocation

return mylocation

end run


Script: “Convert Mac to Windows path”


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 myClip to the input

set mytext to searchReplace(myClip, "<", "")

set mytext to searchReplace(mytext, ">.", "")

set mytext to searchReplace(mytext, ">", "")

set mytext to searchReplace(mytext, "smb://", "\\\\")

set findIt to "/"

set replaceIt to "\\"

set mylocation to searchReplace(mytext, findIt, replaceIt)

return mylocation

end run

Screenshots of the scripts:

User uploaded file

User uploaded file

User uploaded file

10 replies
Question marked as Best reply

Mar 12, 2017 2:21 PM in response to Jessta G

Got a wild hair to solve this problem since it's been bugging me… first, I'll recap, then provide a solution +:

PROBLEM

From a Mac, I want to copy a file path on a network share into an email so that its clickable by poor Windows recipients. Currently, I copy/paste the path, e.g.:

smb://servername/MLS/Timbers/IrrefutableProofTimbersAreBestTeamInMLS.pdf

into an email, then manually convert it to a Windows path:

\\servername\MLS\Timbers\IrrefutableProofTimbersAreBestTeamInMLS.pdf


But that’s a stupid thing to do over and over, so I found some examples online (this forum and others) and hacked it until I got it to work a few ways (see below).


A related problem is when Windows users send me a file path and I want to quickly access it. Currently, I manually navigate to it by translating the path in my little head, which hurts. So, I reversed the hack above and added a call to open the folder to the file.

SOLUTION

In Mac OS Automator I created three Apple scripts that run as a service. This enables me to select a path, right-click and choose the appropriate service from the “Services…” menu, which I named:

“Convert Windows to Mac path and open it”

“Convert Windows to Mac path”

“Convert Mac to Windows path”

User uploaded file

DETAILS

Script: “Convert Windows to Mac path and open it”


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 myClip to the input

set mytext to searchReplace(myClip, "<", "")

set mytext to searchReplace(mytext, ">.", "")

set mytext to searchReplace(mytext, ">", "")

set findIt to "\\"

set replaceIt to "/"

set mylocation to searchReplace(mytext, findIt, replaceIt)

set mylocation to "smb:" & mylocation

tell application "Finder"

open location mylocation

end tell

return input

end run


-- Thanks to: http://apple.stackexchange.com/questions/144916/how-to-change-filepath-structure -using-automator-windows-to-mac --

Script: “Convert Windows to Mac path”

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 myClip to the input

set mytext to searchReplace(myClip, "<", "")

set mytext to searchReplace(mytext, ">.", "")

set mytext to searchReplace(mytext, ">", "")

set findIt to "\\"

set replaceIt to "/"

set mylocation to searchReplace(mytext, findIt, replaceIt)

set mylocation to "smb:" & mylocation

return mylocation

end run


Script: “Convert Mac to Windows path”


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 myClip to the input

set mytext to searchReplace(myClip, "<", "")

set mytext to searchReplace(mytext, ">.", "")

set mytext to searchReplace(mytext, ">", "")

set mytext to searchReplace(mytext, "smb://", "\\\\")

set findIt to "/"

set replaceIt to "\\"

set mylocation to searchReplace(mytext, findIt, replaceIt)

return mylocation

end run

Screenshots of the scripts:

User uploaded file

User uploaded file

User uploaded file

Mar 13, 2017 4:05 AM in response to Jessta G

Why are you not using a Web server with common access by PC and Mac users, and where these files are stored? You use a common https URI path to the filename on the webserver, and then PC and Mac specific filesystem nomenclature is no longer necessary.


One should have a data policy in place that offers filenaming conventions for cross-platform compatibility, and a facility where users can drag/drop files onto a web server page, and have those documents placed in the appropriate web server location.

Dec 4, 2013 7:15 AM in response to Jessta G

Could you provide a bit more context? What exactly are you doing?


A file path only has meaning in terms of a file system. On a Mac, you don't have a Windows file system and vice versa. There are ways to export file systems, but then they are different file systems. It all depends on the context and what you are really doing with the path.

Dec 4, 2013 7:42 AM in response to etresoft

etresoft wrote:


A file path only has meaning in terms of a file system.


Quite true. In new development work, I'd look to encode this as a URI, a format that has good and known rules, and could serve as an intermediate format or even the canonical format for the operation.


In the general case, file names and file paths can be far more of a problem than might be initially obvious, as the tools can be forced to deal with host-local conversions and characters and lengths that might not map across operating systems. Which means various filename converters can either ignore these cases, or can end up non-reversable conversions. Microsoft Windows itself has various rules for what's available, depending on the file system.

Dec 5, 2013 1:42 AM in response to etresoft

I work in an office with PC users so I want an application which I can drop a folder/file onto that will extract the server file path (eg. Networkdrive/rootfolder/sub-folder/file) and convert it to the Windows format for me to paste into an email. I would like it (or another application) to then be able to take a Windows file path which I get sent and convert it to an OSX path which I can then go to in Finder.

Dec 5, 2013 6:35 AM in response to Jessta G

Jessta G wrote:


I work in an office with PC users so I want an application which I can drop a folder/file onto that will extract the server file path (eg. Networkdrive/rootfolder/sub-folder/file) and convert it to the Windows format for me to paste into an email. I would like it (or another application) to then be able to take a Windows file path which I get sent and convert it to an OSX path which I can then go to in Finder.


Your application will inherently be PC specific, as the device letters can be adjusted local to each PC. If you've locked that down in your enviroment and if you're never using odd characters in the filename, then a translation can be a hunk of Perl or Python or some other scripting language. Whatever you write will be site-specific, basically parsing the filename and reworking the hunks to match what your local Windows share lettering expects.


This environment is filled with edge cases. It'd probably be easier to do some sort of an "uploader" tool that picked a generated filename (or allowed some choice but still enforced a filename and naming conventions) and an upload location to the share for you, and that avoided all the gnarly bits of this problem. Simplify the problem somewhat, in other words. Upload to share foo with directory bar, and gives you back a generated path and name.

I'd also look at whether traditional file storage and heirarchies are even appropriate for the current environment. You're quite near the edge of a file management or content management system. Where folks upload files to a web interface, and then download those. That eliminates the shares, and it eliminates the filename translations, and it can also be used to manage how long the file is kept around and automatically purge things, track access and protect the files, etc. That's a little more than a filename translation tool, but there are file managment packages around. Off the top, OwnCloud might fit here, for instance.

convert pc file path to Mac and vice versa

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