pythonmacosautomator

Automation to Convert Mac to Windows Paths


I'm migrating to MacOS but most of my organisation works with Windows. We frequently exchange links (via email / teams) to a network drive mapped to "D:\".

I am exploring an automation to convert MacOS filepaths to Windows filepaths using a small python script.

Expected Behaviour

Select Text -> Right-Click -> Services -> AutomationName -> Text gets replaced.

[EDIT: I can tell that the Automation is working because the text does get replaced. The issue is that it gets replaced with "Input", which is being passed onto Python as a string ("Input").

Issue

Steps so far

enter image description here

# Convert MacOS Path to Windows Path

import sys

def MtW(link):
    wPath = link.replace("/Users/FF/Server","D:\\").replace("/","\\")
    print(wPath)

if __name__ == '__main__':
    globals()[sys.argv[1]](sys.argv[2])

Thank you for your support.


Solution

  • I found the solution for this. Perhaps it can be helpful to others.

    The selected text gets stored in a variable called "$1/".

    In case it helps anyone - here it is:

    enter image description here