Hello, I’m picking up AppleScript and have a problem of understaning some how AppleScript copes with handles with labeled paramters.
Consider the following script
set myName to "Agnar Renolen"
set wifeName to replace of myName into "Jana" instead of "Agnar"
set authorName to replace of myName into "Mykle" instead of "Renolen"
set aFarmer to replace of myName into "rari" instead of "nar Renol"
set stillMyName to replace of myName into "Blabla" instead of "Blabla"
to replace of aString into newStr instead of subStr
set iStart to offset of subStr in aString
if iStart is 0 then
return aString
end if
set iEnd to iStart + (length of subStr)
if iStart is 1 then
set str1 to ""
else
set str1 to (text from character 1 to character (iStart - 1) of aString)
end if
set iLast to count characters in aString
if iEnd is greater than iLast then
set str2 to ""
else
set str2 to (text from character iEnd to character iLast of aString)
end if
return str1 & newStr & str2
end replace
This script works as intended. But:
1)Why can’t I replace “of” with “from” in the handler declaration, i.e:
to replace from aString into newStr instead of subStr
This generates a compiler error.
2) How can I call this handler from within a tell block. I can’t find a syntax that works?
(It works if I redeclare the handler to have positional parameters)