/ Id-Extras Forum / FormMaker Pro – Combo Box Export Values / Reply To: FormMaker Pro – Combo Box Export Values

#7086
Keltexan
Participant

    I have found and used a script called “Combo Mambo,” written by Chuck Weger. You can set up a list in a text file in Notepad or Notepad ++ and import the list into a combo box by running the script in InDesign. Below is a copy of the script with instructions on how to load the script into InDesign.

    #target InDesign
    // A script to fill in the choice list of a listbox or combobox in InDesign CS6, given a text file on disk.
    // Written by Chuck Weger <cweger@elara.com> for Sandee Cohen at the NYC InDesign Users Group, September 13, 2012
    // Updated by Chuck Weger 9/14/12 to filter for ONLY plain text files.
    // Updated by Chuck Weger 1/16/14 to work with InDesign CC
    
    // Copyright © 2012, Chuck Weger
    // This script may be freely distributed, copied, repurposed, chopped, diced, sliced, etc. But I would appreciate attribution.
    
    // USAGE:
    // 1. In InDesign, select (using the Selection Tool) a Combo Box or List Box
    // 2. Run this script
    // 3. When prompted, select a plain text file that contains the text you want in the list or combo box
    // 4. There is no step 4.
    
    if (app.selection.length) {
    var s = app.selection[0];
    if (s.constructor.name == "ComboBox" || s.constructor.name == "ListBox") { // avoid dealing with objects we can't process
    var theList = getTheList();
    if (theList) {
    if (theList.length) {
    s.choiceList = theList;
    }
    else {
    alert("There was a problem reading this text file. Sorry.");
    }
    }
    }
    else {
    alert("Please choose a ComboBox or Listbox with the direct selection tool first.");
    }
    }
    else {
    alert("Please choose a ComboBox or Listbox with the direct selection tool first.");
    }
    
    function getTheList() {
    // ask the user for a plain text file, then read that file in and split it up into lines
    var theList = [];
    var theFile = getOneTextFile("Please select a plain text file.");
    if (theFile) {
    if (theFile.open("r")) {
    var theListStr = theFile.read();
    theFile.close();
    theList = theListStr.split("\n"); // somehow this magically works cross-platform, even though it shouldn't!
    }
    }
    else { // user canceled the Open dialog
    theList = null;
    }
    return theList;
    }
    
    function getOneTextFile(prompt) {
    // returns a file object that points to a text (.txt) file
    var myFile = null;
    // set the file filter; this is different depending upon the platform
    if ($.os.indexOf("Mac") >= 0) { // this is running on a Mac
    var filter = filterTextFiles;
    }
    else {
    var filter = "Text files:*.txt"
    }
    var myFile = File.openDialog(prompt, filter);
    return myFile;
    }
    
    function filterTextFiles(f) {
    // a file filter, used for Mac OS X only
    var suffix = f.name.substr(f.name.length - 4).toUpperCase();
    if (suffix == ".TXT" || f.constructor.name == "Folder") {
    return true;
    }
    else {
    return false;
    }
    }