Skip to content

Instantly share code, notes, and snippets.

@shapiro125
Last active March 9, 2019 18:38
Show Gist options
  • Save shapiro125/c93dd2a322b1f28b9c03ada085bef997 to your computer and use it in GitHub Desktop.
Save shapiro125/c93dd2a322b1f28b9c03ada085bef997 to your computer and use it in GitHub Desktop.
MacOS Service to convert file path on server to Windows file path and copy to clipboard
# Using Automator -> File -> New -> Service -> Run Applescript
# setting up the basic search and replace function
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}
# Convert path to string for the search and replace
set macPath to POSIX path of (input as string)
# Run the search and replace
set winPath to searchReplace(macPath, "<", "")
set winPath to searchReplace(winPath, ">.", "")
set winPath to searchReplace(winPath, ">", "")
set winPath to searchReplace(winPath, "\\", "/")
# Replace the MacOS volume names with Windows drive letters
set winPath to searchReplace(winPath, "/Volumes/shared", "S:")
set winPath to searchReplace(winPath, "/Volumes/comm", "P:")
set the clipboard to winPath
# Convert clipboard to plain text so that it doesn't change the font in Microsoft applications
do shell script "pbpaste | pbcopy"
#Just so you know it's done
display notification "Windows path copied to clipboard"
return input
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment