-
-
Save shapiro125/553fee765c8b0b777c712a925b316f4b to your computer and use it in GitHub Desktop.
An Automator service to convert Windows network links to MacOS Finder paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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} | |
#performing the search and replace function on specific characters in the file path | |
set myClip to the input | |
set mylocation to searchReplace(myClip, "<", "") | |
set mylocation to searchReplace(mylocation, ">.", "") | |
set mylocation to searchReplace(mylocation, ">", "") | |
set mylocation to searchReplace(mylocation, "\\", "/") | |
set mylocation to "smb:" & mylocation | |
#replacing the Windows letter drives with the mounted MacOS volume | |
set mylocation to searchReplace(mylocation, "smb:S:", "/Volumes/shared") | |
set mylocation to searchReplace(mylocation, "smb:s:", "/Volumes/shared") | |
set mylocation to searchReplace(mylocation, "smb:P:", "/Volumes/comm") | |
set mylocation to searchReplace(mylocation, "smb:p:", "/Volumes/comm") | |
tell application "System Events" | |
# check to see if the file or folder exists at all so the whole thing doesn't crash | |
if exists mylocation then | |
# open the file or folder | |
tell application "Finder" to open (mylocation as POSIX file) | |
# display the program because the files open in the background | |
if mylocation contains ".doc" then | |
tell application "Microsoft Word" to activate | |
else if mylocation contains ".xls" then | |
tell application "Microsoft Excel" to activate | |
else if mylocation contains ".ppt" then | |
tell application "Microsoft PowerPoint" to activate | |
else | |
#for folder links | |
tell application "Finder" to activate | |
end if | |
# display a dialog if the file doesn't exist | |
else | |
display dialog "The file does not exist." | |
end if | |
end tell | |
return input | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment