Ms word 在Applescript中,在TextEdit中仅查找粗体字会导致应用程序挂起
只是想找到一种普通的applescript方法,将变量设置为文档中所有粗体字。我一直在寻找在Word、Pages和TextEdit中使用Applescript的方法,TextEdit似乎是唯一的一种(尽管可能是错误的) 好消息是下面的脚本可以工作,但坏消息是如果文档超过2页,比如说50个粗体字,TextEdit将挂起 使用Applescript获取粗体字还有其他方法吗Ms word 在Applescript中,在TextEdit中仅查找粗体字会导致应用程序挂起,ms-word,applescript,textedit,Ms Word,Applescript,Textedit,只是想找到一种普通的applescript方法,将变量设置为文档中所有粗体字。我一直在寻找在Word、Pages和TextEdit中使用Applescript的方法,TextEdit似乎是唯一的一种(尽管可能是错误的) 好消息是下面的脚本可以工作,但坏消息是如果文档超过2页,比如说50个粗体字,TextEdit将挂起 使用Applescript获取粗体字还有其他方法吗 tell application "TextEdit" return words of text of document
tell application "TextEdit"
return words of text of document 1 where font contains "Bold"
end tell
谢谢可能是文本编辑速度太慢了。我刚刚将以下代码用于一个3600字的文档,其中有一些随机的粗体字。时间太长了。我会考虑使用不同的可编写脚本的应用程序,比如Tex Edit Plus(仍然强大,仍然很棒)。 我同时使用“黑色”和“粗体”的原因是,当您将文本设置为粗体时(至少在TextEdit中),某些字体使用“黑色”变体而不是“粗体”。需要明确的是,下面的代码可以工作,但速度非常慢。如果您等待的时间足够长,那么您的代码可能也能正常工作-(但请继续阅读:-) 我刚刚在Tex Edit Plus中运行了此文本,它在大约两秒钟内完成:
tell application "Tex-Edit Plus"
tell document 1
set thisManyRuns to count of style run of text of it
repeat with r from 1 to thisManyRuns
set thisStyle to style of style run r of text of it
if on styles of thisStyle contains bold then
--do stuff
set color of style run r of text of it to {0, 35555, 0}
end if
end repeat
end tell
end tell
。。。所以你可能想换个角度。需要注意的是,在查询styles属性上的
之前,我必须将样式
放入thisStyle
变量中——如果我尝试在一行中执行此操作,则不会起作用。我当时正在处理一个rtf文件。(实际上,还不到这个数字。处理一个3600字的文档需要1.4秒)
tell application "Tex-Edit Plus"
tell document 1
set thisManyRuns to count of style run of text of it
repeat with r from 1 to thisManyRuns
set thisStyle to style of style run r of text of it
if on styles of thisStyle contains bold then
--do stuff
set color of style run r of text of it to {0, 35555, 0}
end if
end repeat
end tell
end tell