Start executable via script

How can I start an executable, via the backgroundscript, when a certain logic function (in my case 1060) gets active in my DHD?

I’ve used a script to open a certain web page. See below. You can change from the browser to cmd.exe(I assume) and change the URL to be your required command.

Edit: if you don’t want to see the CMD prompt, you can do ShellExecuteHidden instead :blush:

const
URL = 'https://www.yr.no/nb/v%C3%A6rvarsel/timetabell/1-72837/Norge/Oslo/Oslo/Oslo?i=0';

BROWSER = 'C:\Program Files\Google\Chrome\Application\chrome.exe';

begin
    ShellExecute(BROWSER, URL);
end.

Thanks, that makes sense and now I see what I did wrong.

The second part of my question is also something I totally cannot figure out; how can the script see a cange in the logic function of my DHD? I think I should find the solution somewhere here: procedure RequestLogic(iAddress: word); but I don’t understand it.

It’s rather one of these, depending on what you want to achieve:

procedure OnDHDCommand(Remote: IDHDRemote; ID: cardinal; Len: integer; Data0, Data1, Data2, Data3, Data4, Data5, Data6, Data7: byte);
begin
end;

procedure OnDHDFaderOn(Remote: IDHDRemote; FaderNo: integer; State: boolean);
begin
end;

procedure OnDHDFaderPFL(Remote: IDHDRemote; FaderNo: integer; State: boolean);
begin
end;

procedure OnDHDFaderLevel(Remote: IDHDRemote; FaderNo: integer; Level: SmallInt);
begin
end;
1 Like

I want the script to execute a program when logic function 1060 of the DHD gets 1.

I see this in the monitor:

Logic1060

So my script looks like this:

procedure OnDHDCommand(Remote: IDHDRemote; ID: cardinal; Len: integer; Data0, Data1, Data2, Data3, Data4, Data5, Data6, Data7: byte);
begin
  if (ID = $110E0000) AND (Data0 = 4) AND (Data1 = 24) AND (Data2 = 1) then 
   begin
     [Start Executable];
   end;
end;

When I took the picture the Logic Function 1060 did go to 0, but in the code I put Data2=1, because the script needs to activtate when it gets 1

But nothing happens…

For evaluation put a system log entry into the script:

procedure OnDHDCommand(Remote: IDHDRemote; ID: cardinal; Len: integer; Data0, Data1, Data2, Data3, Data4, Data5, Data6, Data7: byte);
begin
  if (ID = $110E0000) AND (Data0 = 4) AND (Data1 = 24) AND (Data2 = 1) then 
    begin
      SystemLog('ID = ' + IntToStr(ID) + '; Data0 = ' + IntToStr(Data0) + '; 
        Data1 = ' + IntToStr(Data1) + '; Data2 = ' + IntToStr(Data2));
    end;
end;

I tried but nothing is written in the System Log

Then try it without the if-condition.

Just to confirm, you do have license which includes DHD modules right?

Only like this?

procedure OnDHDCommand(Remote: IDHDRemote; ID: cardinal; Len: integer; Data0, Data1, Data2, Data3, Data4, Data5, Data6, Data7: byte);
begin
      SystemLog('ID = ' + IntToStr(ID) + '; Data0 = ' + IntToStr(Data0) + '; 
        Data1 = ' + IntToStr(Data1) + '; Data2 = ' + IntToStr(Data2));
 end;

Nothing happens

@Mongstaen Yes I have

:slightly_frowning_face: Experts, please?  

This should be simple, the background scripts have a callback for DHD logic changes. Try this:

procedure OnDHDLogic(Remote: IDHDRemote; LogicNo: integer; State: boolean);
begin
  if LogicNo = 1060 and State then ShellExecute('D:\NotAVirus.exe', '');
end;

begin
end.

Please note it doesn’t check which DHD-remote/device triggered the logic number (should only be relevant if you have multiple DHD-devices configured in the remote controls).

Also make sure the script is activated as a background-script in the settings. Just running the script won’t work.

Thanks for your answer, I made a test.mls file with only this code:

procedure OnDHDLogic(Remote: IDHDRemote; LogicNo: integer; State: boolean);
begin
  if LogicNo = 1060 and State then ExecuteCommand('AUTOMATION 1 ON');
end;

begin
end.

I used ExecuteCommand(‘AUTOMATION 1 ON’) only for testing, if this works I can focus on the executable.

But as soon as I save the file I get an error in the system log:

10-07-24 15:17:49 Error Error loading background script C:\documents\Settings\mAirList\test.mls: [Error] (3:31): Type mismatch

Now I think I should also include a State so I tried State = 1 and State = true and State =‘true’ and State = “true” but the error stays.

I might’ve missed some brackets (didn’t test it), so try this one:

procedure OnDHDLogic(Remote: IDHDRemote; LogicNo: integer; State: boolean);
begin
  if (LogicNo = 1060) and State then ExecuteCommand('AUTOMATION 1 ON');
end;

begin
end.
1 Like

YES!!! This works, thank you sooooo much! :blush: :blush:

1 Like

@mgie One more question; where did you find this procedure “OnDHDLogic”, it’s not mentioned anywhere on the site (Or I didn’t look in all the places), even not in the DHD wiki. So I was wondering are there more DHD commands/procedures available which I don’t know…

There is a file in the root directory of your mAirList-installation (or the zip-file, if you used that), named Background Script Template.mls. It includes all callback-functions that mAirList will call if the correspondig event happens.
If you scroll down you will find these DHD-specific functions:

// Available in DHD module:

procedure OnDHDCommand(Remote: IDHDRemote; ID: cardinal; Len: integer; Data0, Data1, Data2, Data3, Data4, Data5, Data6, Data7: byte);
begin
end;

procedure OnDHDFaderOn(Remote: IDHDRemote; FaderNo: integer; State: boolean);
begin
end;

procedure OnDHDFaderPFL(Remote: IDHDRemote; FaderNo: integer; State: boolean);
begin
end;

procedure OnDHDFaderLevel(Remote: IDHDRemote; FaderNo: integer; Level: SmallInt);
begin
end;

procedure OnDHDLogic(Remote: IDHDRemote; LogicNo: integer; State: boolean);
begin
end;

AFAIK some functions are currently not available due to recent changes in the code (maybe @Torben could tell more about the current status).
We use OnDHDLogic, that definitely works. OnDHDFaderOn and OnDHDFaderPFL can be substituted if you use the Logic-callback with the corresponding logic-ID.