PushTagsandRegisters; // Works with WinEdt 5.6 and 6.0 (the macro LstGetItem is bugged in WinEdt 5.5). // Weakness of that macro : script and images names must not contain spaces! However, the method used for Choice.edt can be adapted here... StopWorking; // register 6 contains the key word. For example "title", "drawing",... CMD("Backspace");Mark(0); LetReg(6, "%W" ); Declare("fileok"); // that variable will allow to stop the macro whenever something modifies the file during the execution of the macro Assign("fileok","%f"); Declare("sumatra"); Assign("sumatra","%b\Exec\Sumatra\SumatraPDF.exe"); // path of sumatra executable file IfFileExists( "%b\Macros\LaTeX\Choice\%!6\*.pdf", "Relax;", "Prompt('File does not exist, or put some spaces before the keyword...');PopTagsandRegisters;End;" ); LstEnum( "%b\Macros\LaTeX\Choice\%!6", " "); // counts the number of items separated by a space in the path LstGetCount(5); // that number is saved in register 5 ListFolderFiles(8,"%b\Modeles\%!6",".pdf",0,2); // creates a list (string), with at first the path and then the list of all the .pdf files LstEnum( "%!8", " "); // creates a list, separating items each time a space is found LstGetCount(8); // the number of items is saved in register 8 // Generally, there are lore items than real .pdf files, because of spaces in the path LetRegNum(9,%!5); // initialization. There are %!5 items in the path. :Loop:: // registre 7 = [name the current pdf] IfNum(%!9,%!8,'>=','LetRegNum(9,%!5);'); // go back to start if the loop variable gets over the number of .pdf files IfNum(%!9,%!5,'<','LetRegNum(9,%!8-1);'); // go to the end if the loop variable corresponds to an item of the path. Note: last item is number n-1 LstGetItem(7,%!9); // register 7 gets the item corresponding to the loop variable GetFileName( "%!7", 7 ); // but it has to be converted into a file name //Prompt("%!7"); Run(*%$("sumatra"); -reuse-instance "%b\Macros\LaTeX\Choice\%!6\%!7.pdf"*,"%P",0,0,"%!7",1);Wait(250); GetExitCode(2); Loop(!|IfStr("%f","%$('fileok')","<>","CloseAppl('%!7');PopTagsandRegisters;End;");> IfKeyDown(39,0,0,'CloseAppl("%!7");LetRegNum(9,%!9+1);JMP("Loop");',> 'WaitForMessage(10,1);');> IfKeyDown(37,0,0,'CloseAppl("%!7");LetRegNum(9,%!9-1);JMP("Loop");',> 'WaitForMessage(10,1);');> // to escape the macro : Esc key IfKeyDown(27,0,1,'CloseAppl("%!7");PopTagsandRegisters;End;','WaitForMessage(10,1);');> GetExitCode(1);IfStr("%!1","%!2","<>","PopTagsandRegisters;End;");> IfKeyDown(13,0,1,'CloseAppl("%!7");> JMP("Write");','> WaitForMessage(10,1);');|); :Write:: IfFileExists("%b\Macros\LaTeX\Choice\%!6\%!7.tex","Relax;","Prompt(`There is no script for that image, or the names does not correspond`);PopTagsandRegisters;End;");> ReadFile( "%b\Macros\LaTeX\Choice\%!6\%!7.tex",0);> Goto(0);SelWord(1);CMD("Backspace");Mark(1);Ins("%!0");Mark(2);Goto(1);> Exe("%b\Menus\Tools\Next Bullet.edt");> IfOK( "Relax;", "Goto(2);" ); PopTagsandRegisters;End;