我正在尝试在以下脚本中使用 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