Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. token = "PASTE TOKEN HERE"
  2. mcIcon = "/Applications/Media Center 24.app/Contents/Resources/AppIcon.icns"
  3. trackKey = nil
  4.  
  5. function systemKey(key)
  6. hs.eventtap.event.newSystemKeyEvent(string.upper(key), true):post()
  7. hs.eventtap.event.newSystemKeyEvent(string.upper(key), false):post()
  8. end
  9.  
  10. function xmlParse(data,item)
  11. result = data:match("<Item Name=\""..item.."\">(.-)</Item>")
  12.  
  13. if result == nil then
  14. result = ""
  15. else
  16. string.format(result)
  17. end
  18.  
  19. return result
  20. end
  21.  
  22. function mcNotify()
  23. hs.timer.doAfter(
  24. 1,
  25. function()
  26. hs.http.asyncGet("http://localhost:52199/MCWS/v1/Playback/Info?Token="..token.."", {}, function(code,body,headers)
  27. if code == 200 then
  28. if trackKey ~= xmlParse(body, "FileKey") then
  29. trackKey = xmlParse(body, "FileKey")
  30. notif = hs.notify.new({title=xmlParse(body, "Artist"), informativeText=xmlParse(body, "Name")})
  31. notif:contentImage(hs.image.imageFromURL("http://localhost:52199/"..xmlParse(body, "ImageURL").."&Token="..token))
  32. notif:setIdImage(mcIcon)
  33. notif:send()
  34. end
  35. end
  36. end)
  37. end
  38. )
  39. end
  40.  
  41. hs.hotkey.bind({}, "f1", function()
  42. systemKey("BRIGHTNESS_DOWN")
  43. end, nil, function()
  44. systemKey("BRIGHTNESS_DOWN")
  45. end)
  46.  
  47. hs.hotkey.bind({}, "f2", function()
  48. systemKey("BRIGHTNESS_UP")
  49. end, nil, function()
  50. systemKey("BRIGHTNESS_UP")
  51. end)
  52.  
  53. hs.hotkey.bind({}, "f5", function()
  54. systemKey("ILLUMINATION_DOWN")
  55. end, nil, function()
  56. systemKey("ILLUMINATION_DOWN")
  57. end)
  58.  
  59. hs.hotkey.bind({}, "f6", function()
  60. systemKey("ILLUMINATION_UP")
  61. end, nil, function()
  62. systemKey("ILLUMINATION_UP")
  63. end)
  64.  
  65. hs.hotkey.bind({}, "f7", function()
  66. hs.http.get("http://localhost:52199/MCWS/v1/Playback/Previous?Token="..token)
  67. mcNotify()
  68. end)
  69.  
  70. hs.hotkey.bind({}, "f8", function()
  71. hs.http.get("http://localhost:52199/MCWS/v1/Playback/PlayPause?Token="..token)
  72. end)
  73.  
  74. hs.hotkey.bind({}, "f9", function()
  75. hs.http.get("http://localhost:52199/MCWS/v1/Playback/Next?Token="..token)
  76. mcNotify()
  77. end)
  78.  
  79. hs.hotkey.bind({}, "f10", function()
  80. systemKey("MUTE")
  81. end)
  82.  
  83. hs.hotkey.bind({}, "f11", function()
  84. systemKey("SOUND_DOWN")
  85. end, nil, function()
  86. systemKey("SOUND_DOWN")
  87. end)
  88.  
  89. hs.hotkey.bind({}, "f12", function()
  90. systemKey("SOUND_UP")
  91. end, nil, function()
  92. systemKey("SOUND_UP")
  93. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement