Build string of last names form a list of artists and roles

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

Build string of last names form a list of artists and roles

Post by Dick99999 » Sun May 26, 2013 1:28 pm

When I record music from an Internet radio transmissions, I like to include the artist names (Musicals, Opera or Operetta) in the name of the recorded file. I always had to edit the announcements, since they include the character played and voice type for example, not just a list a names.

By using this script bound to a hot key, the selected text in the (active) Browser announcement is taken, and a string of just the last names (or first and last) is displayed for editing and then put on the clipboard

===edit
- Version info now included in code

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
CapsOff
ScrollOff
// for debug:
//SetFocus>Firefox*
// Versions:
// 1.1 - handles more special character as separators including spaces, 
//       most new ones interfere with regular expressions
// 1.2 - Edit of result possibe, EOL deleted if present in result
// 1.3 - Enter (CR) and/or New Line (LF) as name seperator implemented
// 1.4 - Closing parenthis now also end of name option
// 1.5 - made the dcipt interactive, edit result (last anmes artists) on screen now possible
//
// Script reads list of character roles and performing artists out of last active app
// Script outputs  a list of last names only on the clipboard  
//
// Input must have been selected in the last active app
// First char of selection must be the begin of a name separator. List may contain new line and return characters.
// See examples at the end of the script
//
// Option in script for getting both first and last name
let>lastNameOnly=yes
//
// Set separator between names in in output line and option to include first names
let>sepaResult=,
// in case LF CR are end of name symbols, replace these by sepaForEOL
let>sepaForEOL=}
// copy raw list form last active app and get it in CastAll
press CTRL
send>c
wait>0.2
release CTRL
GetClipBoard>castAll
// change return and linefeed so they look like an end separator
concat>castAll,sepaEnd
StringReplace>castAll,CR,sepaForEOL,castAllX
StringReplace>castAllX,LF,sepaForEOL,castAll

// find begin and end of name seperator in list ( can be , . ; :)
**BREAKPOINT**
MidStr>castAll,1,1,sepaBeg
// if selection starts with an Alfa character, both begin end are spaces
let>pattern=([a-zA-Z])
RegEx>pattern,sepaBeg,0,dummy,nFound,0
if>nFound<>0
   let>sepaBeg=Space
   let>specialSepa=1
endif>
// and find first  symbol, assume that is a end of name separator
let>pattern=.{3,3}([,\.\(;:\}])

RegEx>pattern,castAll,0,seperators,nFound,0
MidStr>seperators_1,4,1,sepaEnd

// split cast in artist names array
// first handle (escape) seperators that have special meaning in regex

**BREAKPOINT**
if>sepaBeg=(
   let>escBeg=\%sepaBeg%
else>
   let>escBeg=sepaBeg
endif>
if>sepaEnd=(
   let>escEnd=\%sepaEnd%
else>
   let>escEnd=sepaEnd
endif>
let>pattern=(%escBeg%.*?%escEnd%)
RegEx>pattern,castAll,0,names,nCast,0
let>castOut=
let>num=0
// concatenate all last names into the out string
while>num<nCast
**BREAKPOINT**
   let>num=num+1
   let>nameCur=names_%num%
   // replace start of name symbol, end of name symbol ans trim lead/trailing spaces
   if>sepaBeg<>space
    StringReplace>nameCur,sepaBeg,,nameCur
   endif>
   StringReplace>nameCur,sepaEnd,,nameCur
   Trim>nameCur,nameCur
   if>lastNameOnly=yes
     // get last name only if requested by option
     let>pattern=.*?(\s+|$)
     RegEx>pattern,nameCur,0,firstLastName,nFound,0
     let>nameCur=firstLastName_%nFound%
   endif
   // and builf output tsring
   let>castOut=%castOut%%nameCur%%sepaResult%
endwhile>
// if eol substitue present replave by space
StringReplace>castOut,sepaForEOL,Space,castOut
Let>MSG_STAYONTOP=1
Let>INPUT_TIMEOUT=0
Let>INPUT_PASSWORD=0
Let>INPUT_BROWSE=0
Input>castOut,edit,castOut
PutClipBoard>castOut

//
// Example:Ennani by G. Verdi Dalyvauja V. Urmana, L. Tézier, M. Giordani, C. Faus, 
// M. Cornetti, A. Rosalen. Dirigentas R. Palumbo,
//     the text selected as input would have to start at the space before Urmana
//     output: Urmana,Tézier,Giordani,Faus,Cornetti,Palumbo,
//
// Example personaggi ed interpreti: sì: margherita vivian, sopr; vera: amelia felle,
// sopr; palmira: marina gentile, msopr; luciano di chablis: mauro nicoletti,
// ten; cleo de mérode: antonio comas, ten; romal: giulio liguori,
// bs; orch sinf del cantiere internazionale d'arte di montepulciano e coro "symbolon 
// ensemble" dir. sandro sanna - m° del coro: donato martorella (reg. 1987)
//     the text selected would start at the colon
//     output: vivian,felle,gentile,nicoletti,comas,liguori,
//
// Example: Mit Nicola Alaimo (Guillaume Tell), Helena Rasker (Hedwige), Eugénie Warnier (Jemmy),
// Marina Rebeka (Mathilde), John Osborn (Arnold Melchtal) u. a.
// Chor und Orchester der Netherlands Opera; Dirigent: Paolo Carignani
//     the text selected as input would have to start at the space after Mit (before the first name Nicola)
//     output: Alaimo,Rasker,Warnier,Rebeka,Osborn,
//
// Example:
//
//
//Doña Luisa, the Indian Queen... Julia Bullock
//Doña Isabel..................... Nadine Koutcher
//Ixbalanque..................... Christophe Dumaux
//Mayan hero.................... Vince Yi
//Don Pedrarias................. Markus Brutscher
//Don Pedro de Alvarado......... Noah Stewart
//Mayan Priest.................. Luthando Qave
//Leonor......................... Maritxell Carrero
//Mayan gods..................... Burr Johnson
//     the text selected as input would have to start at J of Julia
//     output: Bullock,Koutcher,Dumaux,Yi,Brutscher,Stewart,Qave,Carrero,Johnson,Kitamura,Scranton,Singh,Williams,

Last edited by Dick99999 on Sun Jul 27, 2014 3:27 pm, edited 9 times in total.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sun May 26, 2013 10:31 pm

It seems to be your macro sharing.
Or is it a tech issue?
I like your crystal-clear perfect documentation.

Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

Post by Dick99999 » Mon May 27, 2013 8:15 am

Thanks. I have edited my posting, it's a contribution to the 'script data base'. I must say that I liked writing the script more than writing the comments. But the comments do help if you look at your own script after a few month.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon May 27, 2013 8:30 am

Dick99999,
You should correspond with Phil Pendlebury. He is a MS guru here and an inspiring musician--a rare combination. For your listening pleasure, please visit http://www.pendlebury.biz/music.
Happy scripting!

Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

Post by Dick99999 » Wed Sep 18, 2013 11:56 am

Since this post has been viewed over 3000 times, I just wanted to let readers know that I maintain this script and publish it here. (now at version 1.4)

Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

Re: Build string of last names form a list of artists and ro

Post by Dick99999 » Sun Jul 27, 2014 3:25 pm

Version 1.5 includes interactive editing of the result

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Build string of last names form a list of artists and ro

Post by armsys » Sun Jul 27, 2014 8:40 pm

Dick99999 wrote:Version 1.5 includes interactive editing of the result
Hi Dick9999,
Thanks for sharing your annual script enhancement.
Would you please include/exhibit your sourcecode here?
Thanks in advance.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts