Applescript-替换字符“;无法获取alias的所有项目";

Applescript-替换字符“;无法获取alias的所有项目";,applescript,Applescript,下面是我重命名文件的代码。代码基本上检查特殊字符,并替换为“quot(下划线) 代码 它抛出“无法获取别名的所有文本项”请注意。选择文件返回别名。您可以使用将app“Finder”告知文件名,获取文件的基本名称: set f to choose file tell application "Finder" to set n to name of f set n to replace(n, "a", "b") tell application "Finder" to set name of f t

下面是我重命名文件的代码。代码基本上检查特殊字符,并替换为
“quot
(下划线)

代码


它抛出“无法获取别名的所有文本项”请注意。

选择文件
返回别名。您可以使用
将app“Finder”告知文件名
,获取文件的基本名称:

set f to choose file
tell application "Finder" to set n to name of f
set n to replace(n, "a", "b")
tell application "Finder" to set name of f to n

on replace(input, x, y)
    set text item delimiters to x
    set ti to text items of input
    set text item delimiters to y
    ti as text
end replace

据我所知,如果您以后不在同一脚本中使用它。

可能没有必要,但这仍然是一种良好的做法。特别是在一个子例程中,它不知道代码本身之外发生了什么。
set f to choose file
tell application "Finder" to set n to name of f
set n to replace(n, "a", "b")
tell application "Finder" to set name of f to n

on replace(input, x, y)
    set text item delimiters to x
    set ti to text items of input
    set text item delimiters to y
    ti as text
end replace