Help needed re increments for variable


#1

I’m trying to archive something with Kantu (for Firefox) but I’m afraid it’s a bit over my head - having virtually no experience with coding.
What I want to do is have Kantu change a variable by 1 increment every time I run a certain script.

As an example, I want Kantu to fill in “There are 23 apples” and the next time I use the script, it should fill in “There are 24 apples”, etc. However, the script should not automatically loop through as I need manual control over some parts of the process I want to (partly) automate. As an example, I upload a picture, I execute the script, it fills in “There are 23 apples”, I finish the rest manually, then I return to the starting point, upload the next picture, this time the script fills in “There are 24 apples” when executed.

Is something like this possible and if yes, how would I go about it?

Many thanks for your help!


#2

If I understand you correctly, you basically need a variable that is stored “forever” and does not get deleted after macro run (global variables can do this) but also not after Kantu is closed.

If you want your data to survive a closing of Kantu, then store (“persist”) it in a CSV file with csvSave and csvRead.

Here is a macro that works. It stores the value in the csv file “csvBucket” and reads the latest value at each run. You can simply copy and paste this code into the “JSON” tab of Kantu:

{
  "CreationDate": "2018-5-23",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://www.typeform.com/help/sandbox/",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore"
    },
    {
      "Command": "comment",
      "Target": "read once to get # of lines",
      "Value": "!errorignore"
    },
    {
      "Command": "csvRead",
      "Target": "csvBucket",
      "Value": ""
    },
    {
      "Command": "if",
      "Target": "!${!statusOk}",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "csv does not yet exist",
      "Value": "varForever"
    },
    {
      "Command": "store",
      "Target": "0",
      "Value": "!csvLine"
    },
    {
      "Command": "store",
      "Target": "0",
      "Value": "varForever"
    },
    {
      "Command": "csvSave",
      "Target": "csvBucket",
      "Value": ""
    },
    {
      "Command": "else",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "read the LAST line of the csv",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "${!csvReadMaxRow}",
      "Value": "!csvReadLineNumber"
    },
    {
      "Command": "csvRead",
      "Target": "csvBucket",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "Assign CSV value to variable",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "${!COL1}",
      "Value": "varForever"
    },
    {
      "Command": "endif",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "false",
      "Value": "!errorignore"
    },
    {
      "Command": "comment",
      "Target": "Increment counter and save new value",
      "Value": ""
    },
    {
      "Command": "storeEval",
      "Target": "${varForever} + 1",
      "Value": "varForever"
    },
    {
      "Command": "store",
      "Target": "${varForever}",
      "Value": "!csvLine"
    },
    {
      "Command": "csvSave",
      "Target": "csvBucket",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "done! - now use the new value",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "New value is ${varForever}",
      "Value": "green"
    },
    {
      "Command": "type",
      "Target": "id=search",
      "Value": "${varForever}"
    }
  ]
}

#3

That’s exactly what I’ve been looking for, thank you very much for your help, @ulrich !