Copy file paths to clipboard in OSX doesn't work with files on a server...workaround not working with multiple files

StackOverflow https://stackoverflow.com/questions/19914478

Question

I'm using automator to achieve this. Here's the applescript code I'm using (found elsewhere on here):

get the clipboard
set the clipboard to (replacement of "/Volumes/" by "afp://servername.com/" for the result)
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
get the clipboard
set the clipboard to (replacement of "/Volumes/" by "afp://servername.com/" for the result)

This works perfectly unless I select multiple files. Can anyone help? This code seems to fail when the input is multiple file paths.

Was it helpful?

Solution

You might use workflows like this:

on run {input, parameters}
    set output to {}
    repeat with f in input
        set end of output to replace(POSIX path of f, "/Volumes/", "afp://servername.com/")
    end repeat
    set text item delimiters to linefeed
    set the clipboard to (output as text)
end run
on replace(input, search, replace)
    set text item delimiters to search
    set ti to text items of input
    set text item delimiters to replace
    ti as text
end replace

sed 's|/Volumes/|afp://servername.com/|'|LC_CTYPE=UTF-8 pbcopy
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top