Advertisement
amralomari

Script with box

Sep 13th, 2022
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.23 KB | Software | 0 0
  1.  
  2.  
  3. //Is called if this script shall be exited.
  4. function stopScript()
  5. {
  6.     scriptThread.appendTextToConsole("log script has been stopped");
  7. }
  8.  
  9. scriptThread.appendTextToConsole('log script has started');
  10.  
  11. /*
  12.  * Converts a number into 2 digit string.
  13.  * @param number The number.
  14.  * @return The string.
  15.  */
  16. function numberToTwoDigitString(number)
  17. {
  18.     number = number.toString()
  19.     if(number.length == 1)
  20.     {
  21.         number = "0" + number;
  22.     }
  23.     return number;
  24. }
  25.  
  26. function currentDateToString()
  27. {
  28.  
  29.     var now = new Date(Date.now());
  30.     var result = numberToTwoDigitString(now.getFullYear());
  31.     result += "-" + numberToTwoDigitString(now.getMonth()+1) ;
  32.     result += "-" + numberToTwoDigitString(now.getDate());
  33.     result += " " + numberToTwoDigitString(now.getHours());
  34.     result += ":" + numberToTwoDigitString(now.getMinutes());
  35.     result += ":" + numberToTwoDigitString(now.getSeconds());
  36.    
  37.     return result;
  38. }
  39.  
  40. /*
  41.  * Create the file name for the log file.
  42.  * @return The created file name.
  43.  */
  44. function createFileName()
  45. {
  46.     var result = "RD-079";
  47.    
  48.     var now = new Date(Date.now());
  49.     result += "_" + numberToTwoDigitString(now.getFullYear());
  50.     result += "-" + numberToTwoDigitString(now.getMonth()+1) ;
  51.     result += "-" + numberToTwoDigitString(now.getDate());
  52.     result += "_" + numberToTwoDigitString(now.getHours());
  53.     result += "-" + numberToTwoDigitString(now.getMinutes());
  54.     result += "-" + numberToTwoDigitString(now.getSeconds());
  55.  
  56.     result += ".doc";
  57.     return result;
  58. }
  59.  
  60. function dataReceivedSlot(data)
  61. {
  62.    
  63.     g_receivedData = g_receivedData.concat(data);
  64.    
  65.     if(conv.byteArrayToString(g_receivedData).indexOf("Name:")  != -1)
  66.     {
  67.         writeDataToFile();
  68.     }
  69. }
  70. var input = scriptThread.showTextInputDialog("Title", "label", "initial text");
  71. if(input != "")
  72. {
  73. scriptThread.appendTextToConsole("ok button pressed: input=" + input);
  74. }
  75. else
  76. {
  77. scriptThread.appendTextToConsole("ok button not pressed or empty input");
  78. }
  79.  
  80. function writeDataToFile()
  81. {
  82.     var dataToWrite =  currentDateToString()+ input + conv.byteArrayToString(g_receivedData);
  83.    
  84.     scriptFile.writeFile(createFileName(), true, dataToWrite, true);
  85.     g_receivedData = Array();
  86. }
  87.  
  88. var g_receivedData = Array();
  89. scriptInf.dataReceivedSignal.connect(dataReceivedSlot)
  90.  
  91.  
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement