Script to check a file on the web & execute command

Maybe a strange script request :slight_smile: but I want to test something :slight_smile:
I tried to find the solution with chatGPT , via Google Search & via this forum … nothing works …

I’d like to have an (.mls) script, that if you run the script (manually), it will check a simple txt file on the web. If the content of this txt file is (for example) “0”, then the following command must be send to mairlist :
ExecuteCommand(‘PLAYLIST 1 NEXT’);

The script must check this txt file every second.
Once the command to mairlist is given, the script may stop.

What is the usecase? You can read a file using curl. In a shellexecute…

But every second…?

Yes, I want to test something to start a player once the content of the file is a certain word. So he must read a txt file (on the web) every second.
Then (and only then), the script can continue with the script to start te player with the command : ExecuteCommand(‘PLAYLIST 1 NEXT’);
This command is not running all the time. Only when I manually start the script via an event or so.

The script in human words →

  • Check htttps://www.mywebsite.com/file-to-check.txt
  • if content of file is NOT equal to “start” then wait 1 second & check again.
  • If content of file = “start” then execute : ExecuteCommand(‘PLAYLIST 1 NEXT’);
    & quit script.

Dificult to explain my usecase, but I really want it to work :frowning: :frowning:

What if you flip it around, don’t have a file and use the REST module? Would that work for you?

You could remotely ask mAirlist to do the same with the REST API.

I know and this could maybe the best solution but I saw somewhere that the home edition of mAirlist does not support this.

Hey Skeleton.
Sorry but I cannot support making a workaround to avoid the larger/more expensive license.

I do however believe the solution you are proposing is possible with a script. I believe the building blocks are available in the forum if you spend the hours.

Good luck!
Thomas.

const
  URL = 'https://www.mywebsite.com/file-to-check.txt';

var
  sl: TStringList;

procedure OnLoad;
begin
  EnableTimer(1000);
end;

procedure OnTimer;
begin
  sl := TStringList.Create;
  try
    sl.Add(HTTPGet(URL));
    if sl[0] = '0' then
      ExecuteCommand('PLAYLIST 1 NEXT');
  finally
    sl.Free;
  end;
end;

begin
end.

1 Like

[Error] (9:3): Unknown identifier ‘EnableTimer’

:question:

EnableTimer is an approved procedure/method in mAirList Script. For me, it does work. Sorry. (Which version do you run?)

I’m testing the script with Mairlist 7.4.3 Advanced Server (Home)
but it need to be running on Mairlist 7.4.3 Home Studio later on :slight_smile:

I created an MLS file & put this code into this MLS file.
I start this script with an “event” (manually)

Little Update : The code give by “Tondose” works perfectly if I use it as a “background script” (via mAirlist control panel).

When I use the script with an “event”, it gave me the error code
[Error] (9:3): Unknown identifier ‘EnableTimer’