0

I found this script to change uppercase and lowercase of characters in messages but i want to modify this code to replace some string in text, for ex: message received is "i want to eat", this message will be change to "i like to eat" or ":)" change to ":-)".

property lowercaseCharacters : "abcdefghijklmnopqrstuvwxyz"
property uppercaseCharacters : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
on intercaps(str)
set theCharacters to characters of str
set theCount to 1
repeat with aChar in theCharacters
if (aChar is in uppercaseCharacters or aChar is in lowercaseCharacters) then
if (theCount mod 2) is equal to 1 then
set contents of aChar to character (offset of aChar in lowercaseCharacters) of uppercaseCharacters
else
set contents of aChar to character (offset of aChar in uppercaseCharacters) of lowercaseCharacters
end if
end if
set theCount to theCount + 1
end repeat
return theCharacters as string
end intercaps
using terms from application "Messages"
on message sent theMessage for theChat
return intercaps(theMessage)
end message sent
on message received theMessage from theBuddy for theChat
return intercaps(theMessage)
end message received
on chat room message received theMessage from theBuddy for theChat
return intercaps(theMessage)
end chat room message received  
end using terms from

1 Answer 1

0

Here is one method:

set myText to replace_chars("i want to eat", "want", "would like")

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.