0

我正在尝试在以下脚本中使用 replaceChars 函数,但出现以下错误:

error "Finder got an error: Can’t continue replace_chars." number -1708

目的是将脚本作为按钮添加到 finder,以便我可以简单地单击它来将路径复制到我的剪贴板。我正在添加 file://localhost/ 以便在通过电子邮件与用户共享时可以使用该链接作为本地网络上文件夹的直接链接。如果可能的话,我还想为 Windows 机器添加相同的剪贴板。

如果您能就上述任务提供任何指导,将不胜感激,这是我第一次尝试使用 applescript 进行编程,所以我对事情的完成方式并不了解。

继承人的代码:

on appIsRunning(appName)
    tell application "System Events"
        set isRunning to ((application processes whose (name is equal to appName)) count)
    end tell

    if isRunning is greater than 0 then
        return true
    else
        return false
    end if
end appIsRunning

on replace_chars(this_text, search_string, replacement_string)
    set AppleScript's text item delimiters to the search_string
    set the item_list to every text item of this_text
    set AppleScript's text item delimiters to the replacement_string
    set this_text to the item_list as string
    set AppleScript's text item delimiters to ""
    return this_text
end replace_chars

if appIsRunning("Finder") then
    tell application "Finder"
        set thePath to "file://localhost/" as text
        set theTarget to (target of front Finder window) as text
        set the clipboard to thePath & replace_chars(theTarget, ":", "/") as text
    end tell
end if
4

3 回答 3

3

replace_charsAppleScript 正在Finder 的脚本字典中寻找处理程序。您可以让它my replace_chars在脚本中查看 AS,或者(可能更好)将该set the clipboard to thePath & replace_chars(theTarget, ":", "/") as text行完全移出 tell 块。

于 2013-01-16T14:58:05.517 回答
2

你可以把它变成一个单行脚本:

tell application "Finder" to set the clipboard to "file://localhost" & (target of front Finder window as text)'s POSIX path
于 2013-01-16T16:38:46.263 回答
0

将您的replace_chars(theTarget, ":", "/")电话替换为replace_chars(theTarget, ":", "/") of me

set the clipboard to thePath & replace_chars(theTarget, ":", "/") of me as text
于 2013-01-16T20:49:07.580 回答