16 Replies Latest reply on Mar 5, 2014 9:25 AM by camilo umana

# How to merge alphabetically two lists through a rational solution?

Have two lists of captions it two languages and need to merge alphabetically, but this solution is very poor.

(list x)

Palacio Imperial, Barcelona, 2012

Cementerio, 2009

(list y)

Imperial Palace

Cemetery

to obtain:

Palacio Imperial, Barcelona, 2012

Imperial Palace

Cementerio, 2009

Cemetery

One method very naive:

· number the lists

· convert numbering to text

· in list y add a constant to sort in order:

1. Palacio Imperial, Barcelona, 2012

2. Cementerio, 2009

1a. Imperial Palace

2a. Cemetery

and sort:

1. Palacio Imperial, Barcelona, 2012

1a. Imperial Palace

2. Cementerio, 2009

2a. Cemetery

delete the code:

Palacio Imperial, Barcelona, 2012

Imperial Palace

Cementerio, 2009

Cemetery

(italics are not required)

Thanks.

• ###### 1. Re: How to merge alphabetically two lists through a rational solution?

Hi Camilo,

Can you provide us a longer list?

• ###### 2. Re: How to merge alphabetically two lists through a rational solution?

Without thinking a lot, here is an easy way:

1st list: convert in table (Tab1) + add a second column to the right.

2nd list: convert in table (Tab2).

If I understand correctly, there are the same number of cells.

Copy Tab2 instead of the second column of Tab1.

Convert the resulting table (Tab1-2) in text

Search: tab, replace by: \r

• ###### 3. Re: How to merge alphabetically two lists through a rational solution?

Yes, it is a better solution!

Just one step and no more.

Thank, Obi.

• ###### 4. Re: How to merge alphabetically two lists through a rational solution?

Camilo,

You idea is not naive. I like it too!

• ###### 5. Re: How to merge alphabetically two lists through a rational solution?

Camilo,

Another more original way with QuicKeys! [I love this little soft for a long time!] Only 1 click!

For it, you need to use a different paragraph style for each list [eg. List1_Style and List2_Style].

Eg, our list:

A1

A2

A3

A4

B1

B2

B3

B4

Search: (?<=\r)(.+\r)+

Search format: List1_Style

Search-Research Windows must be open into ID.

Shorcut in QuicKeys:

1rst research

1/ Click on the button: Search (actived - in blue)

A2

A3

A4

is selected.

2/ Cut it (shortcut: Apple+X)

3/ Down arrow (of the keyboard)

4/ Copy it

We obtain:

A1

B1

A2

A3

A4

B2

B3

B4

2nd research

1/ Click on the button: Search (actived - in blue)

A3

A4

is selected.

2/ Cut it (shortcut: Apple+X)

3/ Down arrow (of the keyboard)

4/ Copy it

We obtain:

A1

B1

A2

B2

A3

A4

B3

B4

3rd research

1/ Click on the button: Search (actived - in blue)

A4

is selected.

2/ Cut it (shortcut: Apple+X)

3/ Down arrow (of the keyboard)

4/ Copy it

We obtain:

A1

B1

A2

B2

A3

B3

A4

B4

The research stops automatically.

The last work (after this test) is to create a loop in QuicKeys to run the steps 1/-2/-3/-4/ as many times as necessary until the end of the process.

• ###### 6. Re: How to merge alphabetically two lists through a rational solution?

Obi,

Quickeys was having problems with Maverick and I switched to Keyboard maestro.

Both are were terrible stable and tuned.

But tables is perfect for this little problem.

Thank you.

• ###### 7. Re: How to merge alphabetically two lists through a rational solution?

I knew there was another tip to make it, directly in ID.

With 4 regex and Multi-Find/Change.

We have the same list and we need to use a different paragraph style for each list [eg. List1_Style and List2_Style].

A1

A2

A3

A4

B1

B2

B3

B4

We only have to put manually a first paragraph A0:

A0

A1

A2

A3

A4

B1

B2

B3

B4

Regex 1:

Search: (.)\$

Replace by: \$0@

Search format: List1_Style

Regex 2:

Search: (.)\$

Replace by: \$0#

Search format: List2_Style

So we obtain:

A0@

A1@

A2@

A3@

A4@

B1#

B2#

B3#

B4#

Regex 3:

Search: (?<=@\r)((.+@\r)+)(.+#\r)

Replace by: \$3\$1

So:

A0@

B1#

A1@

B2#

A2@

B3#

A3@

B4#

A4@

Regex 4:

Search: (@|#)\$

Replace by: nothing

So:

A0

B1

A1

B2

A2

B3

A3

B4

A4

To do it with several clicks, create:

a MFC1 set and copy in it the regex 1 and the regex 2: 1 click.

a MFC2 set and copy in it the regex 3 (10 times): several clicks to treat the totality of the list.

a MFC1 set and copy in it the regex 4: 1 click.

Finally, delete the first paragraph.  Good WE!

• ###### 8. Re: How to merge alphabetically two lists through a rational solution?

Obi!

This is a very very nice idea as somebody may interchanges different levels of information without scripting!

I am sure this method will help in many situations to move text mechanically (magically).

Thansk for your time and devotion.

• ###### 9. Re: How to merge alphabetically two lists through a rational solution?

If the 2 lists can be in separate text frames like this:

Then this Apple script combines the 2 lists in frame 1—you have to select both frames and I'm assuming the 2 lists have an equal number of items:

=====================

set t to selection

if (count of every item of selection) is 2 then

set t1 to parent story of item 1 of selection

set t2 to parent story of item 2 of selection

else

display dialog "Please Select 2 text frames"

return

end if

--make a temporary text frame

set listframe to make text frame with properties {geometric bounds:{0.5, 0.5, 10.5, 8}} at page 1 of active document

repeat with i from 1 to number of items in every paragraph of t1

set contents of insertion point -1 of listframe to contents of paragraph i of t1 & contents of paragraph i of t2 & return

end repeat

set contents of t1 to contents of parent story of listframe

delete listframe

end tell

==================

This is the result:

• ###### 10. Re: How to merge alphabetically two lists through a rational solution?

Hi Rob,

Very cool [AS]! Thanks.

• ###### 11. Re: How to merge alphabetically two lists through a rational solution?

Rob, this script writes a perfect epilogue on this theme.

Unfortunately, it has a little problem.

(works only in CS6?)

Hope the output is:

• ###### 12. Re: How to merge alphabetically two lists through a rational solution?

Sorry, it's an AppleScript so it won't work on Windows

• ###### 13. Re: How to merge alphabetically two lists through a rational solution?

No, I am in Mac.

I was very orthodox in the saving.

set t to selection

if (count of every item of selection) is 2 then

set t1 to parent story of item 1 of selection

set t2 to parent story of item 2 of selection

else

display dialog "Please Select 2 text frames"

return

end if

--make a temporary text frame

set listframe to make text frame with properties {geometric bounds:{0.5, 0.5, 10.5, 8}} at page 1 of active document

repeat with i from 1 to number of items in every paragraph of t1

set contents of insertion point -1 of listframe to contents of paragraph i of t1 & contents of paragraph i of t2 & return

end repeat

set contents of t1 to contents of parent story of listframe

delete listframe

end tell

• ###### 14. Re: How to merge alphabetically two lists through a rational solution?

Here's a compiled version in a zip archive

http://www.zenodesign.com/forum/ListMerge.zip

• ###### 15. Re: How to merge alphabetically two lists through a rational solution?

Your screen capture is showing that you saved it with a .jsx (JavaScript) extention. You have to paste Applescript code into AppleScript Editor click Compile and save from there—text editors won't work.