{"id":3292,"date":"2025-04-13T19:52:03","date_gmt":"2025-04-13T19:52:03","guid":{"rendered":"https:\/\/devicejockey.de\/?page_id=3292"},"modified":"2026-01-03T12:15:25","modified_gmt":"2026-01-03T12:15:25","slug":"scripts","status":"publish","type":"page","link":"https:\/\/devicejockey.de\/?page_id=3292","title":{"rendered":"Scripts"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>[vc_row el_class=&#8221;welcomebox&#8221; css=&#8221;.vc_custom_1707149624705{margin-bottom: 20px !important;padding-bottom: 5px !important;}&#8221;][vc_column][vc_row_inner][vc_column_inner width=&#8221;1\/2&#8243;][vc_column_text css=&#8221;&#8221;]<\/p>\n<h1>Scripts<\/h1>\n<p>[\/vc_column_text][\/vc_column_inner][\/vc_row_inner][vc_column_text css=&#8221;&#8221;]Bring your panel to the next level with the power of JavaScript![\/vc_column_text][\/vc_column][\/vc_row][vc_row css=&#8221;.vc_custom_1707045863978{background-color: rgba(15,0,0,0.3) !important;*background-color: rgb(15,0,0) !important;}&#8221; el_class=&#8221;.grayBox&#8221; el_id=&#8221;interfaces&#8221;][vc_column][vc_column_text css=&#8221;&#8221;]<\/p>\n<p class=\"\" data-start=\"196\" data-end=\"391\">With scripts in <strong data-start=\"369\" data-end=\"381\">Commands<\/strong> and <strong data-start=\"386\" data-end=\"396\">Events<\/strong>, you can run simple JavaScript code.<br data-start=\"433\" data-end=\"436\" \/>You have access to all <strong data-start=\"459\" data-end=\"468\">Swaps<\/strong> inside your script and can use them like variables \u2013 just refer to the exact name.<\/p>\n<p>[\/vc_column_text][vc_message message_box_color=&#8221;success&#8221; icon_fontawesome=&#8221;fa fa-solid fa-hand-point-up&#8221; css=&#8221;&#8221;]Using <code data-start=\"558\" data-end=\"571\">\\(swapname)<\/code> is also possible, but before execution it will be replaced with the current value of the swap.[\/vc_message][\/vc_column][\/vc_row][vc_row css=&#8221;.vc_custom_1703005440459{background-color: rgba(15,0,0,0.3) !important;*background-color: rgb(15,0,0) !important;}&#8221; el_class=&#8221;.grayBox&#8221;][vc_column][vc_column_text css=&#8221;&#8221;]<\/p>\n<h1 data-start=\"2729\" data-end=\"2767\">Command Script<\/h1>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row css=&#8221;.vc_custom_1703005440459{background-color: rgba(15,0,0,0.3) !important;*background-color: rgb(15,0,0) !important;}&#8221; el_class=&#8221;.grayBox&#8221;][vc_column][vc_column_text css=&#8221;&#8221;]A command script is executed when the <strong data-start=\"2329\" data-end=\"2340\">command<\/strong> is triggered.<br data-start=\"2354\" data-end=\"2357\" \/>The <strong data-start=\"2361\" data-end=\"2396\">output of the script is ignored<\/strong> \u2013 command scripts are not used to control an item directly.<br data-start=\"2456\" data-end=\"2459\" \/>Instead, they typically update Swaps and control other elements of the panel.[\/vc_column_text][vc_column_text css=&#8221;&#8221;]<\/p>\n<h2 data-start=\"2538\" data-end=\"2604\">Send Local Command<\/h2>\n<p class=\"\" data-start=\"2538\" data-end=\"2604\">You can send a local value command directly from any command script.<\/p>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>sendCommand(\"\/test\", \"Hello\") \/\/ sends \"Hello\" to \/test\r\nsendCommand(\"\/test\", 10) \/\/ sends 10 to \/test\r\nsendCommand(\"\/test\", 10, \"float\") \/\/ sends 10 as float to \/test\r\nsendCommand(\"\/test\", 10.5, \"int\") \/\/ sends 10 as int to \/test\r\nsendCommand(\"\/test\", 1, \"bool\") \/\/ sends true as bool to \/test\r\nsendCommand(\"\/test\", true, \"bool\") \/\/ sends true as bool to \/test<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221;]<\/p>\n<h2>Art-Net Commands<\/h2>\n<p>When using Art-Net interfaces, an Art-Net script command allows you to update DMX channel values.[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>sendArtNet(128, 1) \/\/ updates channel 1 to 128 in 8Bit\r\nsendArtNet(128, 1, 2) \/\/ updates channels 1 and 2 to 128 16-bit. Decimal places are possible.\r\n<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221;]<\/p>\n<h2>OSC Commands<\/h2>\n<p>OSC Out interfaces and Behringer\/Midas interfaces allow you to send OSC commands using OSC Script or BX Script commands.[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>\/\/ Send OSC command:\r\nlet arguments = [[\"Example\"], [10, \"int32\"], [20, \"float\"], [true, \"bool\"]]\r\nsendOSC(\"\/test\", arguments)<\/pre>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row css=&#8221;.vc_custom_1703005440459{background-color: rgba(15,0,0,0.3) !important;*background-color: rgb(15,0,0) !important;}&#8221; el_class=&#8221;.grayBox&#8221;][vc_column][vc_column_text css=&#8221;&#8221;]<\/p>\n<h1 data-start=\"2729\" data-end=\"2767\">Event Script<\/h1>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row css=&#8221;.vc_custom_1707045863978{background-color: rgba(15,0,0,0.3) !important;*background-color: rgb(15,0,0) !important;}&#8221; el_class=&#8221;.grayBox&#8221;][vc_column][vc_column_text css=&#8221;&#8221;]Event scripts run automatically. For example, when switching to Live Mode, powering up Interfaces, or whenever a Swap used in the script changes. The return value of the script is used to control the item.<\/p>\n<p>The following example sets a slider to the middle position:[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>let slider = 0.5\r\nslider \/\/ this sets the slider to the middle<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221;]You could also write this shorter:[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>0.5 \/\/ sets the slider directly<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221;]Or use a more complex calculation:[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>if (DLY_MidiSync == 1) {\r\n  let time = 60 \/ midiBPM\r\n  let range = 3\r\n  let sliderValue = time \/ range\r\n  sliderValue\r\n}<\/pre>\n<p>[\/vc_column_text][vc_message message_box_color=&#8221;success&#8221; icon_fontawesome=&#8221;fa fa-solid fa-hand-point-up&#8221; css=&#8221;&#8221;]If the script <strong data-start=\"1413\" data-end=\"1432\">returns nothing<\/strong>, the item will not be affected. This gives you control over whether the item should be influenced by the script or not.[\/vc_message][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>void 0 \/\/ use this line to return \"nothing\"<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221;]<\/p>\n<h2>Local Events<\/h2>\n<p>An event script can respond to local events.<br \/>\nUse the function <strong>getEventValue(path)<\/strong>, where path is the local event\u2019s path.<br \/>\nYou\u2019ll receive the value that was sent to that path.[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>let value = getEventValue(\"\/test\") \/\/ get the value sent by \"\/test\"\r\n\r\n<span style=\"color: #ff0000;\">\/\/ Checking whether you have received a value from \"\/test\" before reacting is important!<\/span>\r\nif (typeof value !== \"undefined\") {\r\n   \/\/ value received from that path\r\n} else {\r\n   \/\/ no value received from that path\r\n}<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221;]<\/p>\n<h2 data-start=\"1840\" data-end=\"1858\">Remote Options<\/h2>\n<p class=\"\" data-start=\"1860\" data-end=\"1995\">Inside your script, you can also configure <strong data-start=\"1903\" data-end=\"1921\">remote options<\/strong>, which determine which commands should be triggered by this event script:<\/p>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>remote(\"all\", true) \/\/ enables \"send all triggers\"\r\nremote(\"all\", false) \/\/ disables all\r\nremote(\"d\", true\/false) \/\/ sets \"disable control\"\r\nremote(\"s\", true\/false) \/\/ sets \"system event\"\r\nremote(\"1\"..\"20\", true\/false) \/\/ enables or disables trigger 1\u201320<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221;]<\/p>\n<h2 data-start=\"1840\" data-end=\"1858\">Set Item Color<\/h2>\n<p class=\"\" data-start=\"1860\" data-end=\"1995\">Set the color of your Item with the following functions:<\/p>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>\/\/ RGB\r\n\r\n\/\/ background color\r\nlet red = 255 \/\/ 0..255\r\nlet green = 0 \/\/ 0..255\r\nlet blue = 0 \/\/ 0..255\r\n\r\n\/\/ optional textcolor\r\nlet redTxt = 255 \/\/ 0..255\r\nlet greenTxt = 0 \/\/ 0..255\r\nlet blueTxt = 0 \/\/ 0..255\r\n\r\nsetColorRGB(red, green, blue) \/\/ colors only the Item\r\nsetColorRGB(red, green, blue, redTxt, greenTxt, blueTxt) \/\/ colors the Item and the text\r\n\r\n\/\/ HSL\r\n\r\n\/\/ background color\r\nlet hue = 360 \/\/ 0..360\r\nlet saturation = 100 \/\/ 0..100\r\nlet lightness = 50 \/\/ 0..100\r\n\r\n\/\/ optional textcolor\r\nlet hueTxt = 360 \/\/ 0..360\r\nlet saturationTxt = 100 \/\/ 0..100\r\nlet lightnessTxt = 50 \/\/ 0..100\r\n\r\nsetColorHSL(hue, saturation, lightness, hueTxt, saturationTxt, lightnessTxt) \/\/ colors the Item and the text\r\nsetColorHSL(hue, saturation, lightness) \/\/ colors only the Item<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221;]<\/p>\n<h2>Behringer\/Midas and OSC Label<\/h2>\n<p>In the Label Event of the Behringer\/Midas and the OSC interface, you can format the incoming arguments using a script.<br \/>\nThe first received argument is available as <strong>labelValue<\/strong>. Get all arguments as an array with <strong>oscArguments<\/strong>.<\/p>\n<p>The output of your script will be displayed as the label.<\/p>\n<h3>Example<\/h3>\n<p>Converting a value from 0\u20131 into a frequency from 200 Hz to 20 kHz.<br \/>\nYou will get 200 to 999, 1k, 1.5k, 20k[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>const maxF = 20000\r\nconst minF = 200\r\nconst x = Math.min(Math.max(0.0, labelValue), 1.0)\r\nconst m = maxF \/ minF\r\nconst frequency = minF * Math.pow(10.0, x * Math.log10(m))\r\n\r\nformatFrequency(frequency)\r\n\r\nfunction formatFrequency(frequency) {\r\n   if (frequency &lt; 1000) {\r\n     return Math.round(frequency).toString()\r\n   } else {\r\n     const k = frequency \/ 1000\r\n     const rounded = Math.round(k * 10) \/ 10\r\n     return (rounded % 1 === 0 ? rounded.toFixed(0) : rounded.toFixed(1)) + 'k'\r\n   }\r\n}<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>console.log(oscArguments) \/\/ Print all received arguments in the logging view<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221;]<\/p>\n<h2>Behringer\/Midas and OSC Script<\/h2>\n<p>Process the OSC event in the script. You can access the received arguments with the <strong>oscArguments<\/strong> array.[\/vc_column_text][vc_column_text css=&#8221;&#8221;]<\/p>\n<h2>MIDI Clock<\/h2>\n<p>With the MIDI In interface, you can use a script inside the MIDI Clock event to process MIDI Clock data.[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>midiBar \/\/ current bar\r\nmidiBeat \/\/ current beat\r\nmidiBPM \/\/ current BPM\r\nmidiStarted \/\/ true if clock started from stop\r\nmidiStopped \/\/ true if clock stopped\r\nmidiContinued \/\/ true if clock continued from pause<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>console.log(swapA) \/\/ shows \"swapB\"\r\nconsole.log(getSwapValue(swapA)) \/\/ shows 10<\/pre>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row css=&#8221;.vc_custom_1703005440459{background-color: rgba(15,0,0,0.3) !important;*background-color: rgb(15,0,0) !important;}&#8221; el_class=&#8221;.grayBox&#8221;][vc_column][vc_column_text css=&#8221;&#8221;]<\/p>\n<h1 data-start=\"2729\" data-end=\"2767\">Swaps In Scripts<\/h1>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row css=&#8221;.vc_custom_1703005440459{background-color: rgba(15,0,0,0.3) !important;*background-color: rgb(15,0,0) !important;}&#8221; el_class=&#8221;.grayBox&#8221;][vc_column][vc_column_text css=&#8221;&#8221;]You can use swaps in scripts in two ways:<\/p>\n<h3>Swap Name<\/h3>\n<p>Use the swap name directly to read or change a swap\u2019s value.[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]console.log(mySwap) \/\/ The value of the swap, e.g. 10 or &#8220;Hello&#8221;<\/p>\n<p>mySwap = &#8220;Hello world&#8221; \/\/ Sets the value of the swap to &#8220;Hello world&#8221;[\/vc_column_text][vc_column_text css=&#8221;&#8221;]<\/p>\n<h3 data-start=\"198\" data-end=\"228\">Escaped Swap <code data-start=\"215\" data-end=\"228\">\\(swapName)<\/code><\/h3>\n<p data-start=\"229\" data-end=\"325\">Use the escaped swap name if you want to replace part of the script with the swap\u2019s value.<\/p>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]console.log( &#8220;Hello \\(mySwap)&#8221; ) \/\/ &#8220;Hello world&#8221;[\/vc_column_text][vc_column_text css=&#8221;&#8221;]<\/p>\n<h3>Swap Values<\/h3>\n<p>[\/vc_column_text][vc_message message_box_color=&#8221;success&#8221; icon_fontawesome=&#8221;fa fa-solid fa-hand-point-up&#8221; css=&#8221;&#8221;]A swap can contain another swap as its value.[\/vc_message][vc_column_text css=&#8221;&#8221;]<\/p>\n<h3>Example<\/h3>\n<p>swapA = \\(swapB)<br \/>\nswapB = 10<\/p>\n<p>You always get the swap value when you use the variable name.<br \/>\nUse the <strong>getSwapValue()<\/strong> function to retrieve the fully replaced value.[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]console.log(swapA) \/\/ Prints \\(swapB)<\/p>\n<p>console.log( getSwapValue(swapA) \/\/ Prints 10[\/vc_column_text][\/vc_column][\/vc_row][vc_row css=&#8221;.vc_custom_1703005440459{background-color: rgba(15,0,0,0.3) !important;*background-color: rgb(15,0,0) !important;}&#8221; el_class=&#8221;.grayBox&#8221;][vc_column][vc_column_text css=&#8221;&#8221;]<\/p>\n<h1 data-start=\"2729\" data-end=\"2767\">Functions And Variables in Scripts<\/h1>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row css=&#8221;.vc_custom_1703005440459{background-color: rgba(15,0,0,0.3) !important;*background-color: rgb(15,0,0) !important;}&#8221; el_class=&#8221;.grayBox&#8221;][vc_column][vc_column_text css=&#8221;&#8221;]<\/p>\n<h2 data-start=\"2999\" data-end=\"3014\">Item Status<\/h2>\n<p class=\"\" data-start=\"3016\" data-end=\"3140\">Retrieve the item status in a script.<br \/>\nAll variables are read-only. The item status can not be set.<br \/>\nDepending on the item type, some values \u200b\u200bmay not be available.<\/p>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>itemValue \/\/ e.g. slider position (0\u20131) or toggle state (0 = off, 1 = on)\r\nitemSelected \/\/ true for toggled on, false for off\r\nitemLight \/\/ true if item\u2019s light is on\r\nitemProtected \/\/ true if the item is protected and can\u2019t be controlled<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221;]<\/p>\n<h2 data-start=\"2729\" data-end=\"2767\">console.log<\/h2>\n<p data-start=\"2729\" data-end=\"2767\">Use <strong>console.log()<\/strong> to write messages to the panel&#8217;s logging window.<br \/>\nThe local interface must be selected in the log view to see the messages.[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>console.log(\"This is a status out of the script\")<\/pre>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>console.log(itemValue) \r\nconsole.log(itemSelected) \r\nconsole.log(itemLight) \r\nconsole.log(itemProtected)<\/pre>\n<p>[\/vc_column_text][vc_message message_box_color=&#8221;success&#8221; icon_fontawesome=&#8221;fa fa-solid fa-hand-point-up&#8221; css=&#8221;&#8221;]Enable the local interface in the logging window to view <code data-start=\"287\" data-end=\"300\">console.log<\/code> messages.[\/vc_message][vc_column_text css=&#8221;&#8221;]<\/p>\n<h2 data-start=\"1840\" data-end=\"1858\">Convert RGB HSL<\/h2>\n<p class=\"\" data-start=\"1860\" data-end=\"1995\">Use the following functions to convert RGB to HSL and vice versa:<\/p>\n<p>[\/vc_column_text][vc_column_text css=&#8221;&#8221; el_class=&#8221;codebox&#8221;]<\/p>\n<pre>\/\/ RGB to HSL\r\n\r\nlet hsl = rgb2hsl(red,green,blue)\r\nhue = hsl[\"h\"]\r\nsaturation = hsl[\"s\"]\r\nlightness = hsl[\"l\"]\r\n\r\n\/\/HSL to RGB<\/pre>\n<div>\n<pre>let rgb = hsl2rgb(hue,saturation,lightness)\r\nred = rgb[\"r\"]\r\ngreen = rgb[\"g\"]\r\nblue = rgb[\"b\"]<\/pre>\n<\/div>\n<p>[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>[vc_row el_class=&#8221;welcomebox&#8221; css=&#8221;.vc_custom_1707149624705{margin-bottom: 20px !important;padding-bottom: 5px !important;}&#8221;][vc_column][vc_row_inner][vc_column_inner width=&#8221;1\/2&#8243;][vc_column_text css=&#8221;&#8221;] Scripts [\/vc_column_text][\/vc_column_inner][\/vc_row_inner][vc_column_text css=&#8221;&#8221;]Bring your panel to the next level with the power of JavaScript![\/vc_column_text][\/vc_column][\/vc_row][vc_row css=&#8221;.vc_custom_1707045863978{background-color: rgba(15,0,0,0.3) !important;*background-color: rgb(15,0,0) !important;}&#8221; el_class=&#8221;.grayBox&#8221; el_id=&#8221;interfaces&#8221;][vc_column][vc_column_text css=&#8221;&#8221;] With scripts in Commands and Events, you can run simple JavaScript code.You have access to all Swaps inside your script and can use them&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1634,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3292","page","type-page","status-publish","hentry","description-off"],"_links":{"self":[{"href":"https:\/\/devicejockey.de\/index.php?rest_route=\/wp\/v2\/pages\/3292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devicejockey.de\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/devicejockey.de\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/devicejockey.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/devicejockey.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3292"}],"version-history":[{"count":52,"href":"https:\/\/devicejockey.de\/index.php?rest_route=\/wp\/v2\/pages\/3292\/revisions"}],"predecessor-version":[{"id":3516,"href":"https:\/\/devicejockey.de\/index.php?rest_route=\/wp\/v2\/pages\/3292\/revisions\/3516"}],"up":[{"embeddable":true,"href":"https:\/\/devicejockey.de\/index.php?rest_route=\/wp\/v2\/pages\/1634"}],"wp:attachment":[{"href":"https:\/\/devicejockey.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}