Control iTunes from Node-RED using JavaScript for Automation

This flow allows you to use JavaScript for Automation within Node-RED and control any OS X application that supports it. In this example we toggle iTune's play/pause control.

Any script you would code in Apple's Script Editor (in JavaScript mode) can be entered in the template node.

[{"id":"e219ad98.1de65","type":"subflow","name":"AppleScriptJS","info":"","in":[{"x":95.00000381469727,"y":44.50000476837158,"wires":[{"id":"696f15a7.9690ec"}]}],"out":[{"x":540,"y":40,"wires":[{"id":"777ac03c.88854","port":0}]},{"x":540,"y":100,"wires":[{"id":"777ac03c.88854","port":1},{"id":"777ac03c.88854","port":2}]}]},{"id":"777ac03c.88854","type":"exec","z":"e219ad98.1de65","command":"osascript -l JavaScript -e ","addpay":true,"append":"","useSpawn":"","name":"osascriptJS","x":377.00000381469727,"y":44.00000476837158,"wires":[[],[],[]]},{"id":"696f15a7.9690ec","type":"function","z":"e219ad98.1de65","name":"","func":"msg.payload = `\"${msg.payload}\"`\nreturn msg;","outputs":1,"noerr":0,"x":225.00000381469727,"y":44.50000476837158,"wires":[["777ac03c.88854"]]},{"id":"1fabca00.e05436","type":"template","z":"1a6c15d.fe593ea","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"iTunes = Application('iTunes');\niTunes.playpause();","x":270,"y":880,"wires":[["719a078c.8e65f8"]]},{"id":"719a078c.8e65f8","type":"subflow:e219ad98.1de65","z":"1a6c15d.fe593ea","name":"","x":440,"y":880,"wires":[[],[]]},{"id":"20c06107.df3f9e","type":"inject","z":"1a6c15d.fe593ea","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":120,"y":880,"wires":[["1fabca00.e05436"]]}]
natcl

Flow Info

created 1 year, 8 months ago

Node Types

Core
  • exec (x1)
  • function (x1)
  • inject (x1)
  • template (x1)
Other
  • subflow (x1)
  • subflow:e219ad98.1de65 (x1)

Tags

  • iTunes
  • JavaScript
  • AppleScript
  • Automation
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option