eruption-project / eruption

Realtime RGB LED Driver for Linux
https://eruption-project.org/
GNU General Public License v3.0
270 stars 33 forks source link

How to execute a system function from a macro? #39

Closed Madcliff closed 3 years ago

Madcliff commented 3 years ago

So i recall that it used to be possible to execute a bash command from a macro. What is the correct syntax to do so currently?

X3n0m0rph59 commented 3 years ago

Hi! Shell commands may be run like this:

result = system("/usr/bin/logger", { "-i", "Message from eruption" })
if result ~= 0 then
    error("Command execution failed with result: " .. result)
end

The first parameter to the system function is the command name, the second parameter is a Lua table (roughly equivalent to an array) that specifies the command line parameters of the program being run.

The program will be executed with the rights of the eruption process (root by default). To run the program as a different user you can do the following:

result = system("/usr/bin/sudo", { "DISPLAY=:1", "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus", "-u", "user", "notify-send", "Message", "A message from eruption" })
if result ~= 0 then
    error("Command execution failed with result: " .. result)
end

Please replace "user" and "1000" with the respective user name and ID.