Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- token = "PASTE TOKEN HERE"
- mcIcon = "/Applications/Media Center 24.app/Contents/Resources/AppIcon.icns"
- trackKey = nil
- function systemKey(key)
- hs.eventtap.event.newSystemKeyEvent(string.upper(key), true):post()
- hs.eventtap.event.newSystemKeyEvent(string.upper(key), false):post()
- end
- function xmlParse(data,item)
- result = data:match("<Item Name=\""..item.."\">(.-)</Item>")
- if result == nil then
- result = ""
- else
- string.format(result)
- end
- return result
- end
- function mcNotify()
- hs.timer.doAfter(
- 1,
- function()
- hs.http.asyncGet("http://localhost:52199/MCWS/v1/Playback/Info?Token="..token.."", {}, function(code,body,headers)
- if code == 200 then
- if trackKey ~= xmlParse(body, "FileKey") then
- trackKey = xmlParse(body, "FileKey")
- notif = hs.notify.new({title=xmlParse(body, "Artist"), informativeText=xmlParse(body, "Name")})
- notif:contentImage(hs.image.imageFromURL("http://localhost:52199/"..xmlParse(body, "ImageURL").."&Token="..token))
- notif:setIdImage(mcIcon)
- notif:send()
- end
- end
- end)
- end
- )
- end
- hs.hotkey.bind({}, "f1", function()
- systemKey("BRIGHTNESS_DOWN")
- end, nil, function()
- systemKey("BRIGHTNESS_DOWN")
- end)
- hs.hotkey.bind({}, "f2", function()
- systemKey("BRIGHTNESS_UP")
- end, nil, function()
- systemKey("BRIGHTNESS_UP")
- end)
- hs.hotkey.bind({}, "f5", function()
- systemKey("ILLUMINATION_DOWN")
- end, nil, function()
- systemKey("ILLUMINATION_DOWN")
- end)
- hs.hotkey.bind({}, "f6", function()
- systemKey("ILLUMINATION_UP")
- end, nil, function()
- systemKey("ILLUMINATION_UP")
- end)
- hs.hotkey.bind({}, "f7", function()
- hs.http.get("http://localhost:52199/MCWS/v1/Playback/Previous?Token="..token)
- mcNotify()
- end)
- hs.hotkey.bind({}, "f8", function()
- hs.http.get("http://localhost:52199/MCWS/v1/Playback/PlayPause?Token="..token)
- end)
- hs.hotkey.bind({}, "f9", function()
- hs.http.get("http://localhost:52199/MCWS/v1/Playback/Next?Token="..token)
- mcNotify()
- end)
- hs.hotkey.bind({}, "f10", function()
- systemKey("MUTE")
- end)
- hs.hotkey.bind({}, "f11", function()
- systemKey("SOUND_DOWN")
- end, nil, function()
- systemKey("SOUND_DOWN")
- end)
- hs.hotkey.bind({}, "f12", function()
- systemKey("SOUND_UP")
- end, nil, function()
- systemKey("SOUND_UP")
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement