<p>Does anyone know how to generate SQL scripts from a query?</p>

<p>For example, </p>

<ol>
<li>Script some tables.</li>
<li>Do custom action 1.</li>
<li>Script the views. </li>
<li>Do custom action 2.</li>
<li>Etc.</li>
</ol>

It sounds like you want to write a cursor to execute custom SQL.  This is common and easy to do.  What you need to do is specify a few things to help us more completely answer your question:
What type of SQL server are you using? (MSSQL, Oracle, MySQL)
What language are you writing in? (Java, C++, PL/SQL, TSQL)
You can either write code (Java / C++) to generate SQL from a query, or possibly use a cursor to iterate over recordsets (PL/SQL / TSQL).  You can use the results to give you information that can then be executed as SQL via an exec (of some kind depending on the language).