Search code examples
splitevalextractclipboardimacros

iMacros - Exclude original extracted text from being saved in csv


I hope I'm being clear. I'm a total noob. This is my first time asking a question here, too, so I apologise for missing anything that I should've provided.

So what I wanted to achieve is to save / 'split' certain parts of an extracted string in a csv using EVAL. As a simplified model of what I am trying to achieve, here is a modified code from one of the demos in iMacros:

URL GOTO=http://www.iopus.com/imacros/demo/v6/extract2/       
TAG POS=1 TYPE=P ATTR=CLASS:heading&&TXT:* EXTRACT=TXT  
SET commandOnly EVAL("var s=\"{{!EXTRACT}}\"; s.split(' ')[2];")
ADD !EXTRACT {{commandOnly}}
SAVEAS TYPE=EXTRACT FOLDER=* FILE=Extract_{{!NOW:yyyy-mm-dd<SP>hhh<SP>nnmin}}.csv

As you will see, the resultant csv file will have 2 columns populated. I wanted it to result to only one entry in A1 with the word "COMMAND". Is it possible to copy something to the CLIPBOARD without EXTRACTing it? Coz maybe that way, the original extracted text won't reflect in the csv. I would appreciate any solution or workaround. Thanks!


Solution

  • The problem with your initial code is that you used ADD here

    ADD !EXTRACT {{commandOnly}}

    instead of SET. What this did in your case was adding the value in the variable commandOnly to the value !EXTRACT already had instead of overwriting it as SET does.

    You can just change the ADD to SET and you're good.

    So the full code would be

    URL GOTO=http://www.iopus.com/imacros/demo/v6/extract2/       
    TAG POS=1 TYPE=P ATTR=CLASS:heading&&TXT:* EXTRACT=TXT  
    SET commandOnly EVAL("var s=\"{{!EXTRACT}}\"; s.split(' ')[2];")
    SET !EXTRACT {{commandOnly}}
    SAVEAS TYPE=EXTRACT FOLDER=* FILE=Extract_{{!NOW:yyyy-mm-dd<SP>hhh<SP>nnmin}}.csv
    

    Further information on ADD http://wiki.imacros.net/ADD and SET http://wiki.imacros.net/set