在OSX中将文件路径复制到剪贴板不适用于服务器上的文件...解决方法不使用多个文件

时间:2013-11-11 19:40:45

标签: macos applescript finder automator

我正在使用automator来实现这一目标。这是我正在使用的AppleScript代码(在这里的其他地方找到):

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)

除非我选择多个文件,否则这种方法很有效。有人可以帮忙吗?当输入是多个文件路径时,此代码似乎失败。

1 个答案:

答案 0 :(得分:0)

您可以使用以下工作流程:

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