Applescript替换消息应用程序中发送和接收的消息

Applescript替换消息应用程序中发送和接收的消息,applescript,messages,Applescript,Messages,我发现这个脚本可以更改消息中字符的大小写,但我想修改这个代码来替换文本中的一些字符串,例如:收到的消息是“我想吃”,这个消息将更改为“我喜欢吃”或“:”更改为“:-” 有一种方法: 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 i

我发现这个脚本可以更改消息中字符的大小写,但我想修改这个代码来替换文本中的一些字符串,例如:收到的消息是“我想吃”,这个消息将更改为“我喜欢吃”或“:”更改为“:-”

有一种方法:

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
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