этот код работает, но ...
ваш обработчик:
splittext
должно быть :
splitText(theText, MaxYear, MinYear}
Обратите внимание на круглые скобки вместо фигурных скобок (и верблюжья оболочка тоже).
Вы всегда должны возвращать строку в вашем обработчике:
return "" -- return false
И в цикле повтора выше:
if newname is not "" then -- if newname then
Есть и другие подводные камни: вид х. Это локальная строка, т.е. «Папка» будет «Досье» на французском языке. Возможно, вы должны сделать что-то вроде этого, если вы не из страны, на которой говорят по-английски:
log kind of x
Итак, весь код, который работает на моей машине (10.12.6):
set MaxYear to 2018 set MinYear to 1990 --return splitText("abc2015def", 2018, 1990) tell application "Finder" set allfiles to every item of (choose folder with prompt "Choose the Files you'd like to rename:" with multiple selections allowed) as list -- set allfile to selections repeat with x in allfiles log kind of x if kind of x is "Folder" then -- if xtype is "Folder" then set cname to name of x set newname to my splitText(cname, MaxYear, MinYear) if newname is not "" then set name of x to newname end if end if end repeat end tell on splitText(theText, MaxYear, MinYear) set dyear to MaxYear repeat until dyear < MinYear set AppleScript's text item delimiters to dyear set theTextItems to every text item of theText set AppleScript's text item delimiters to "" if (count of theTextItems) > 1 then return the first item of theTextItems & dyear as string end if set dyear to dyear - 1 end repeat return "" end splitText