bashscreensaverqdbusqdbusxml2cpp

Screen-saver inhibit script


I would like to automatize screen-saver inhibit, when using Firefox's "plugin-container" for flash player in KDE4. I did not write the original script myself, but I fixed it a bit.

    #!/bin/sh
    # Simple script to demonstrate D-Bus usage
    while true
    do
      # read firefox plugin-container cpu usage
      ret=$(top -b -n1 -u "$(whoami)" | gawk '$12 ~ /plugin-containe/ { SUM += $9 }; END { print SUM }')
      if [ -n "$ret" ] && [ "$ret" -gt 15 ]; then
        idle_time=`qdbus org.kde.screensaver /ScreenSaver GetSessionIdleTime`
        if [ "$idle_time" -gt 50 ]; then
          qdbus org.kde.screensaver /ScreenSaver SimulateUserActivity
        fi
      fi

      sleep 50

done

Now when I run the script i get this error:

/home/geo/bin/plugin-containe: line 7: [: 68.75: integer expression expected

I tried to get top to output integer number but I couldn’t.

What can I do to fix?

Regards Georges


Solution

  • If the awk output is the cause of the non-integer value then you can use the awk int() function to truncate the value of SUM to an integer value (i.e. int(SUM)).