AppleScript 有替换功能吗?

pot*_*eno 7 applescript

在 VBA 中,用不同的子字符串替换子字符串非常容易,例如objMsg.Body = Replace(objMsg.Body, "<Month\", Format(dtDate1, "mmmm"))"<Month>"电子邮件正文中的当前月份替换。我以前见过与此类似的问题,但它们已经有几年的历史了,而且往往有疯狂的解决方法,几乎​​不值得我花时间。

mb2*_*b21 10

不,但你可以使用这个(来源):

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
Run Code Online (Sandbox Code Playgroud)

用法:

replace_chars(message_string, "string_to_be_replaced", "replacement_string")
Run Code Online (Sandbox Code Playgroud)

(顺便说一句,你现在也可以使用 JavaScript 而不是 AppleScript,搜索“JavaScript for OS X Automation”)

  • JXA 的问题实际上是零文档、示例或用户支持,以及其 Apple 事件桥和 OSA 组件插件支持中的大量设计缺陷和遗漏。如果您正在编写应用程序脚本,那么 AppleScript 是唯一可以正常工作的官方支持选项。几个可能有帮助的链接:我正在向 [任何想要它的人](http://lists.apple.com/archives/applescript-users/2016/Jun/msg00188.html) 赠送一个 AS“标准库”,以及从其他语言 [通过 AppleScript-ObjC 桥] (http://appscript.sourceforge.net/asoc.html) 调用 AS 处理程序的方法。 (2认同)