# Creating a CDF file from the command line?

I'm working remotely on the Wolfram Engine bundled with the Raspberry Pi and I want to export a manipulatable plot as a CDF without needing to have the front end open. So for example, the following works to export a plot as a png:

plt1=Plot[Cos[x],{x,-6,6}]
UseFrontEnd[Export["~/plt.png",plt1]]


which creates a .png of the desired plot. My naive hope was that I could create a manipulatable plot in much the same fashion, i.e.

plt=Manipulate[Plot[Cos[-x+t],{x,-1,1}],{t,-4,4}]
UseFrontEnd[Export["~/mani.cdf",plt]]


but I see now that hope was misguided as it did not work. Could anyone show me a way to tell the backend to use the frontend to make me a CDF, or is this somehow not possible? All the sources for creating CDFs that I've seen involve going through the menus in a notebook interface which necessitates that I actually interact with the front end which is inconvenient for me.

UseFrontEnd[Export["~/mani.cdf", DocumentNotebook[{plt}]]]

As Gustavo Delfino mentioned, instead of UseFrontEnd from the "JLink" package you might want to use the newer "System" symbol UsingFrontEnd. For a bit more information about the two and their differences see e.g. here UseFrontEnd is not working the same in version 10.4 (documentation for the two seems to be quite minimalistic and especially gives no clear indication about whether one of the two is deprecated or to be favoured...).