【发布时间】:2014-03-10 11:55:55
【问题描述】:
我正在尝试编写一个将通过启动代理运行的applescript。脚本需要做的是编辑用户首选项 plist 文件,以便默认保存位置特定于该用户。我知道这可以通过将“~/documents”设置为模板 plist 中的位置来完成。但例如 Premier Pro 也需要将暂存文件写入本地驱动器。为简单起见,我希望每个用户都根据他们的用户名将它们放在一个位置。只有在首次登录时刚刚从模板创建本地配置文件时,才需要运行此脚本。
我已经开始使用在这个网站上找到的一些示例代码,并在下面进行了一个简单的测试。此测试应编辑一个 txt 文件并将一个单词替换为另一个单词。此脚本当前不工作。测试时,它会在 TextEdit 中打开 test.txt,但什么也不做。也不显示错误。
提前谢谢你
约翰。
replaceText("replace this", "replace with this", "/Volumes/USB_Drive/test.txt")
on replaceText(search_string, replacement_text, this_document)
tell application "TextEdit"
open this_document
set AppleScript's text item delimiters to the search_string
set this_text to the text of the front document as list
set AppleScript's text item delimiters to the replacement_text
set the text of the front document to (this_text as string)
close this_document saving yes
end tell
end replaceText
【问题讨论】:
标签: file text replace find applescript