Zren / plasma-applet-commandoutput

https://store.kde.org/p/1166510/
GNU General Public License v2.0
87 stars 18 forks source link

How can i render output of sudo program? #15

Closed 0xdeafbeef closed 4 years ago

0xdeafbeef commented 4 years ago

For example, i have such command:

echo SSD; sudo smartctl -a  /dev/nvme0 | grep 'Temperature Sensor 1' | grep -o '[0-9].' | sed '2q;d'

which shows temperature of ssd. How can i make your widget to render output of this command?

Zren commented 4 years ago

The widget is run as your user level permissions. That's why that command needs to be run as sudo to elevate your permissions to the root user. First things first, you should NEVER try to run an entire GUI application as root (eg: dolphin). So don't attempt that method, as you'll likely fuckup your KDE install.

In order to do this, you need to "whitelist" that command so that you can run it as a normal user. I came across this a long time ago, but I've never tried it.

Be extremely careful that you don't accidentally allow your user to run any command as root. Good luck.

Zren commented 4 years ago

It looks like you're trying to show your nvme's temperature sensor. Can you currently graph that sensor in KSysGuard? As it might be easier for you to create a widget that displays a sensor value.

PlasmaComponents.Label {
    text: i18n("SSD %1", dataSource.getData(dataSource.nvmeSensorPath))
}
PlasmaCore.DataSource {
    id: datasource
    engine: "systemmonitor"
    property string nvmeSensorPath: '/asdf/asdf/asdf/????'
    connectedSources: [ nvmeSensorPath ]

    function getData(key) {
        if (typeof dataSource.data[key] === 'undefined') return 0
        if (typeof dataSource.data[key].value === 'undefined') return 0
        return dataSource.data[key].value
    }
}
0xdeafbeef commented 4 years ago

I made i crutch:
Created tmpfs, and added script, which writes current temp of ssd to file on tmpfs.
Scripts starts with os.
Thank you for your help!