Skip to content

Instantly share code, notes, and snippets.

@moluapple
Created February 8, 2012 12:11
Show Gist options
  • Save moluapple/1768602 to your computer and use it in GitHub Desktop.
Save moluapple/1768602 to your computer and use it in GitHub Desktop.
[Indesign]Fix text to frame eventListener
/**********************
* 请事先为文本框添加自定义脚本标签"fixwidth"
* 出现溢流后,文本框选中时内容会自动适应文本框
* 非正式脚本,仅用于测试演示目的
*********************/
#targetengine "events"
var doc = app.activeDocument;
/afterSelectionAttributeChanged/.test(doc.eventListeners.everyItem().eventType) || doc.addEventListener("afterSelectionAttributeChanged", fixWidth);
function fixWidth (e) {
var t, s;
if (!app.selection.length || (t = app.selection[0], t.constructor.name != 'TextFrame') || t.label != 'fixwidth') return;
s = t.parentStory;
while (s.overflows) {
s.tracking -= 1, s.horizontalScale -= 3;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment