In some cases it may be desirable to obfuscate the code in Lua scripts and Advanced custom fields and prevent them from being edited. In order to do this, drop a menu.lua script in the data sources Scripts folder, When you next open InDesign this adds a menu option to the data panels pop-out menu which encodes or decodes these scripts. The script requires a key to encode the script and can only be decoded with the same key. Once the data source has been encoded the script can be removed if not required.
Example menu.lua script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | function onbuttonclick_encrypt(dialog) thisdatasource = DATASOURCE.get() widgetKey = dialog:getwidget("key") if widgetKey.content == "" then DIALOG.alert("Please enter a key") return end ok, msg = thisdatasource:encryptlua(widgetKey.content) if ok then myDialog:close() return end DIALOG.alert(msg) end function onbuttonclick_decrypt(dialog) thisdatasource = DATASOURCE.get() widgetKey = dialog:getwidget("key") if widgetKey.content == "" then DIALOG.alert("Please enter a key") return end ok, msg = thisdatasource:decryptlua(widgetKey.content) if ok then myDialog:close() return end DIALOG.alert(msg) end function getname() return "Encrypt/Decrypt" end function updatestate() return true end function dodialog() myDialog = DIALOG.new({title = "Encrypt Advanced Custom Fields and Lua Scripts"}) myDialog:addwidget({type = "statictext", title = "Key:", left = 20, top = 20, width = 60}) myDialog:addwidget({type = "editbox", id = "key", left = 70, top = 20, width = 230}) myDialog:addwidget( { type = "button", title = "Encrypt", id = "encrypt", left = 30, top = 80, width = 80, onclick = "onbuttonclick_encrypt" } ) myDialog:addwidget( { type = "button", title = "Decrypt", id = "decrypt", left = 125, top = 80, width = 90, onclick = "onbuttonclick_decrypt" } ) myDialog:addwidget({type = "cancelbutton", title = "Cancel", left = 230, top = 80, width = 80}) myDialog:open() end MENU.add({where = "palette", gettitle = "getname", onupdate = "updatestate", onselect = "dodialog", position = 1}) |