#target indesign; doc = app.activeDocument; // Collect all text variables defined in the doc. and their values. // Returns two-element array: text_vars[0] contains the names of variables, // text_vars[1], their values. text_vars = text_variables (app.activeDocument); // Show dialog. text_vars[0] is used for the labels, // text_vars[1] for the values in the edit fields. updated_vars = get_updates (text_vars[0], text_vars[1]); // Update the text variables update_variables (app.activeDocument, updated_vars[0], updated_vars[1]); function update_variables (doc, var_names, var_values) { var v = doc.textVariables; for (var i = 0; i < var_names.length; i++) v.item (var_names[i]).variableOptions.contents = var_values[i]; } function text_variables (doc) { var v = doc.textVariables; var v_names = []; //variable names in dialog var v_values = []; //values in dialog for (var i = 0; i < v.length; i++) { if (v[i].variableType == VariableTypes.customTextType) { v_names.push (v[i].name); v_values.push (v[i].variableOptions.contents); } } return [v_names, v_values] } function get_updates (v_names, v_values) // v_names and val are arrays { var w = new Window ('dialog', 'Update text variables'); w.orientation = 'row'; w.alignChildren = ['left', 'top']; var p = w.add ('panel'); p.orientation = 'column'; var g = []; var new_val = []; var s = []; for (var i = 0; i < v_names.length; i++) { g[i] = p.add ('group'); s[i] = g[i].add ('statictext', undefined, v_names[i]); new_val[i] = g[i].add ('edittext'); new_val[i].text = v_values[i]; s[i].preferredSize = [75,20]; new_val[i].preferredSize = [150,20]; } new_val[0].active = true; var button_group = w.add ('group'); button_group.orientation = 'column'; ok_button = button_group.add('button', undefined, 'OK'); ok_button.preferredSize = [80,25]; cancel_button = button_group.add ('button', undefined, 'Cancel'); cancel_button.preferredSize = [80,25]; if (w.show() == 2) exit(); return [v_names, to_text (new_val)] } function to_text (edit_object) { var temp = []; for (var i = 0; i < edit_object.length; i++) temp.push (edit_object[i].text); return temp }