Advertisement
Haron_Prime

pulseaudio.lua

Sep 7th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. local io = io
  2. local math = math
  3. local tonumber = tonumber
  4. local tostring = tostring
  5. local string = string
  6.  
  7. module("pulseaudio")
  8.  
  9. function volumeUp()
  10.     local step = 655 * 5
  11.     local f = io.popen("pacmd dump |grep set-sink-volume")
  12.     local v = f:read()
  13.     f:close()
  14.     if v ~= nil then
  15.       local volume = tonumber(string.sub(v, string.find(v, 'x') - 1))
  16.       local newVolume = volume + step
  17.       if newVolume > 65536 then
  18.           newVolume = 65536
  19.       end
  20.       io.popen("pacmd set-sink-volume 0 "..newVolume)
  21.     end
  22. end
  23.  
  24. function volumeDown()
  25.     local step = 655 * 5
  26.     local f = io.popen("pacmd dump |grep set-sink-volume")
  27.     local v = f:read()
  28.     f:close()
  29.     if v ~= nil then
  30.       local volume = tonumber(string.sub(v, string.find(v, 'x') - 1))
  31.       local newVolume = volume - step
  32.       if newVolume < 0 then
  33.           newVolume = 0
  34.       end
  35.       io.popen("pacmd set-sink-volume 0 "..newVolume)
  36.     end
  37. end
  38.  
  39. function volumeMute()
  40.     local g = io.popen("pacmd dump |grep set-sink-mute")
  41.     local mute = g:read()
  42.     if string.find(mute, "no") then
  43.         io.popen("pacmd set-sink-mute 0 yes")
  44.     else
  45.         io.popen("pacmd set-sink-mute 0 no")
  46.     end
  47.     g:close()
  48. end
  49.  
  50. function volumeInfo()
  51.     volmin = 0
  52.     volmax = 65536
  53.     local f = io.popen("pacmd dump |grep set-sink-volume")
  54.     local g = io.popen("pacmd dump |grep set-sink-mute")
  55.     local v = f:read()
  56.     local mute = g:read()
  57.     if mute ~= nil and string.find(mute, "no") then
  58.         volume = math.floor(tonumber(string.sub(v, string.find(v, 'x')-1)) * 100 / volmax).." %"
  59.     else
  60.         volume = "✕"
  61.     end
  62.     f:close()
  63.     g:close()
  64.     return "𝅘𝅥𝅮  "..volume
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement