问题描述
在选定的 TextFrame 中寻找所有段落的选择器,包括溢流中的“不可见段落”。脚本已经在运行并循环显示可见段落:
[...]
if(app.selection[0].constructor.name=="TextFrame") {
var myParagraphs = app.selection[0].paragraphs; // only visible ones?!
var myArray = myParagraphs.everyItem().contents;
for (var i=0; i<myArray.length; i++) {
// do some fancy styling - WORKING
myParagraphs[i].appliedParagraphStyle = app.activeDocument.paragraphStyles.item('Format XYZ');
}
}
当我为 TextFrame 设置另一个高度时,myArray.length 会发生变化。但是我如何处理所有段落?已经用相同的结果测试了 .anyItem() :(
解决方法
好吧,overset 中的段落不是文本框架的段落,因此在您的脚本中跳过它们是有道理的。要访问文本框架的所有段落 + 溢流部分中的段落,您需要访问父故事的所有段落(故事是描述链接文本框架内所有文本和溢流文本的文本实体)文本框。
你可以这样做:
// profile returns the AWS shared credentials profile. If empty will read
// environment variable "AWS_PROFILE". If that is not set profile will
// return "default".
func (p *SharedCredentialsProvider) profile() string {
if p.Profile == "" {
p.Profile = os.Getenv("AWS_PROFILE")
}
if p.Profile == "" {
p.Profile = "default"
}
return p.Profile
}
请注意,这将处理链接到文本框架的所有文本框架中的所有段落,以防万一。
另外,由于看起来您需要在整个故事的每个段落上应用段落样式,您不妨直接将段落样式应用于整个故事,而不是在段落上循环:
{
"variables": {
"aws_profile": "{{env `AWS_PROFILE`}}"
},"builders": [{
"type": "amazon-ebs","region": "eu-central-1","profile": "{{ user `aws_profile`}}"
[...]