• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

list in alphabetical order

Engaged ,
Oct 06, 2014 Oct 06, 2014

Copy link to clipboard

Copied

In a previous question I asked for a list (https://forums.adobe.com/thread/146710) which "jump_over" solved fantastically.

As so often, once it works people start complaining.

I made the script work with 150 names in it, listed surname name (which is how they have to appear in the text), but with the names are sorted alphabetically on the Name (the list comes from IT dep).

Question: is it possible to get the list in the panel in the alphabetical order sorted on the Name (Name Surname), but when placed the name and surname should reversed.

Below the script. When run, you get a panel with all the names, double click inserts the selection at the cursor point.

Inverting "Name Surname" doesn't do the trick, because in mTitles the order would be oke but the insertion is not oke. I've a script that reverses two words, but sometimes names have more than two words in them (ex John Mac Doe).

Thanks already for looking into it.

  1. #target indesign 
  2. #targetengine mDialog 
  3. var 
  4.   mTitles = ["Surname1 Name1","Surname2 Name2","Surname3 Name3"], 
  5.   w = new Window ("palette","Title multiselector", undefined); 
  6.  
  7. w.alignChildren = "left"
  8. w.add("staticText", undefined, "Doubleclick to choose and add. \r'Delete' button removes last added", {align:"left",multiline: true,closeButton: false}); 
  9.  
  10. var 
  11.   body = w.add("group"), 
  12.   mList = body.add("listbox",undefined,mTitles,{scrollbar: true}), 
  13.   mButt = body.add("group"); 
  14.   mButt.orientation = "column"
  15.   mButt.alignment = "bottom"
  16.   mButt.add("button", undefined, "Delete last"); 
  17.   mButt.add("button", undefined, "Finish"); 
  18.  
  19.   mList.preferredSize = [200,150]; 
  20.  
  21.   mList.onDoubleClick = function() { 
  22.      app.selection[0].contents = mList.selection.text + "\r"
  23.      } 
  24.   mButt.children[1].onClick = function() { 
  25.      w.close(); 
  26.      } 
  27.   mButt.children[0].onClick = function() { 
  28.      app.selection[0].parentStory.lines[-1].remove(); 
  29.      } 
  30.   if (app.selection[0].constructor.name == "InsertionPoint") w.show(); 
  31.   else
  32.      alert("Make a cursor active inside desired text box");  exit(); 
  33.      } 
TOPICS
Scripting

Views

2.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 07, 2014 Oct 07, 2014

Copy link to clipboard

Copied

Hi Gert,

What you need seems to be a custom sort on your array mTitles so that the <Name> part of your entries is considered first during the sorting process. As a primary approach you could simply regard the first SPACE character in the string as a separator between <Surname> and <Name>. This way the order remains relevant even when <Name> contains additional spaces. However, if the <Surname> part allows inner space too, then you need to improve your data structure so that <Surname> and <Name> can be properly identified.

A cool trick is to add hidden keys into an Array object. These keys remain transparent to ScriptUI but can be used to save ordering data for additional sort or display features. Here is an example:

var mTitles = ["Alan Turing", "Steve Jobs", "Bill Gates", "John Mac Doe"];

(function(a,i,k,p)

{

    i = a.length;

    while( i-- )

        {

        p = (k=a).indexOf(' ');

        0 <= p && (k=k.substr(1+p)+', '+k.substr(0,p));

        a['_'+a] = k;

        }

    a.sort(function(x,y){ return x=a['_'+x],y=a['_'+y],(-(x<y)||(x>y)); });

})(mTitles);

// Here your code

var w = new Window("palette", "Title multiselector", undefined);

// etc.

The above function performs two tasks:

• it creates hidden keys in the form "_<ItemString>" associated to <Name>,<Surname> values.

• it reorders mTitles items with respect to those hidden key-value pairs.

This way you can also handle the associated <Name>,<Surname> sequence of any item using the "_" (underscore) prefix.

E.g. mTitles["_John Mac Doe"] => "Mac Doe, John"

Hope that helps.

@+

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 07, 2014 Oct 07, 2014

Copy link to clipboard

Copied

LATEST

@marc: not figured it out yet (being a novice scriptwriter), I'll post a screenshot of what should be happening when running the script.

orderedList.jpg

So, in the list (I receive a xls-list from IT, alphabetically ordered Name Surname, which is good for looking up) they should stay like that but in the text they should appear in the reversed order.

I tried your example, but nothing special happens. I did insert a"_" before a name to see what it gives, but the result is simply the _+ the name (_Almaci Meyrem) gives _Almaci Meyrem after running the script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines