I don't use it normally, but I just tested the following successfully.
texliveonfly must be installed, which it was here. If it isn't installed, you can install it by opening a terminal and typing
sudo tlmgr install texliveonfly
To use this in TeXworks go to Edit --> Preferences, and look under the Typesetting tab. Click the plus-button next to the list of typesetting tools to create a new one. Give it a reasonable name, type
texliveonfly in the Program box and add a new argument
$fullname by (again) clicking the plus-button. See screenshot below.
To compile your document with this, select in the dropdown-menu and click the green arrow (or Ctrl + T). You can also set this as a default for the document by typing
% !TeX program = TeXliveonthefly
TeXliveonthefly was the name you gave that typesetting tool.
As mentioned on the CTAN-page,
lualatex is used as the default compiler. If you want to use e.g.
pdflatex add another argument before