期待一个结束,但发现

Expect an end but find on

我有这样的代码

tell application "app"
    set 1 to something
    repeat with some in 1
        set refpdf to field "File Attachments" of record 1
        on findAndReplaceInText(theText, theSearchString, theReplacementString)
    set AppleScript's text item delimiters to theSearchString
    set theTextItems to every text item of theText
    set AppleScript's text item delimiters to theReplacementString
    set theText to theTextItems as string
    set AppleScript's text item delimiters to ""
    return theText
end findAndReplaceInText
        set refpdf1 to findAndReplaceInText(refpdf, "some", "some2")
        set libh to findAndReplaceInText(libraryname, "test", "test2")
        
    end repeat
end tell

它给我一个错误,但我应该使用 on findAndReplaceInText 命令更改文本,我做错了什么?

三期:

  1. 处理程序必须在脚本的顶层
  2. some为保留字,使用something else
  3. 必须使用 my
  4. 调用应用程序 tell 块中的处理程序

tell application "app"
    set 1 to something
    repeat with somethingElse in 1
        set refpdf to field "File Attachments" of record 1
        set refpdf1 to my findAndReplaceInText(refpdf, "some", "some2")
        set libh to my findAndReplaceInText(libraryname, "test", "test2")
    end repeat
end tell

on findAndReplaceInText(theText, theSearchString, theReplacementString)
    set AppleScript's text item delimiters to theSearchString
    set theTextItems to every text item of theText
    set AppleScript's text item delimiters to theReplacementString
    set theText to theTextItems as string
    set AppleScript's text item delimiters to ""
    return theText
end findAndReplaceInText