Object «script»

This article is automatically translated from Russian by Google Translator.

Represents methods of controlling script execution and accessing operating system functions.

Method

Description

quit

Sets the end-of-run flag for an event-driven program.

random

Returns a random number from the specified range.

readAll

Считывает всё содержимое указанного файла в массив строк.

removeFile

Deletes the specified file.

run

Sets the event-oriented program flag.

system

Выполняет переданную в качестве параметра команду консоли операционной системы.

time

Returns the time stamp - the number of milliseconds elapsed since the beginning of January 1, 1970 GMT.

timer

Creates and returns a timer.

wait

Suspends script execution for the number of milliseconds passed.

writeToFile

Writes a string to a file.

quit

Sets the end-of-run flag for an event-driven program. As soon as the current event handler completes, the script execution will end.

Syntax

JavaScript
Python
JavaScript
script.quit();
Python
script.quit();

random

Returns a random number from the specified range.

Syntax

JavaScript
Python
JavaScript
script.random(min, max);
Python
script.random(min, max);

The range boundaries must be specified as parameters.

Example

JavaScript
Python
JavaScript
var a = script.random(0, 10); // random number from 0 to 10
Python
a = script.random(0, 10); # random number from 0 to 10

readAll

Reads the entire contents of the specified file into a string array.

Syntax

JavaScript
Python
JavaScript
script.readAll('fileName');
Python
script.readAll('fileName');

As a parameter, you must specify the name of the file with the extension.

Example

JavaScript
Python
JavaScript
var lines = script.readAll('input.txt'); // reads the text file input.txt
Python
lines = script.readAll('input.txt'); # reads the text file input.txt

removeFile

Deletes the specified file.

Syntax

JavaScript
Python
JavaScript
script.removeFile('fileName');
Python
script.removeFile('fileName');

As a parameter, you must specify the name of the file with the extension.

Example

JavaScript
Python
JavaScript
script.removeFile('file.txt'); // delete file file.txt
Python
script.removeFile('file.txt'); # delete file file.txt

run

Sets the event-oriented program flag. When the script finishes, it is not unloaded from memory but continues to wait for events to occur until one of the handlers calls the "quit" method.

Syntax

JavaScript
Python
JavaScript
script.run();
Python
script.run();

system

Executes the command transmitted.

Syntax

JavaScript
Python
JavaScript
script.system();
Python
ript.system();

As a parameter, you must specify the operating system console command.

Example

JavaScript
Python
JavaScript
script.system("reboot");
Python
script.system("reboot");

time

Returns the time stamp - the number of milliseconds elapsed since the beginning of January 1, 1970 GMT.

Syntax

JavaScript
Python
JavaScript
script.time();
Python
script.time();

timer

Creates and returns a timer (class QTimer) that sends a timeout signal every n milliseconds.

Syntax

JavaScript
Python
JavaScript
script.timer(n);
Python
script.timer(n);

n is passed as a parameter.

Example

JavaScript
Python
JavaScript
script.timer(1000);
Python
script.timer(1000);

wait

Suspends script execution for the number of milliseconds passed.

Syntax

JavaScript
Python
JavaScript
script.wait(msCount);
Python
script.wait(msCount);

The number of milliseconds is passed as a parameter.

Example

JavaScript
Python
JavaScript
script.wait(1000); // stop the execution of the script for one second
Python
script.wait(1000); # stop the execution of the script for one second

writeToFile

Writes a string to a file.

Syntax

JavaScript
Python
JavaScript
script.writeToFile('fileName', 'text');
Python
script.writeToFile('fileName', 'text');

The file name and the line to be written should be specified as parameters.

Example

JavaScript
Python
JavaScript
script.writeToFile('output.txt', 'Hello, world'); // write "Hello, world" in the output.txt file
Python
script.writeToFile('output.txt', 'Hello, world'); # write "Hello, world" in the output.txt file