"SpreadsheetApp.getUi() cannot be called from this context"
<p>In a Google Sheets spreadsheet, I want to show a modal dialog created from HTML, then run a function, then close that HTML prompt automatically.</p>

<p>The dialog should stay until the function finishes executing, then automatically disappear.</p>

<p>This process has to be repeated every 3 hours, and the script needs to run as me (as I have edit permissions that other users do not) so simple triggers probably won't work (I've read that you must create an installable trigger if you want the function to run as you and not whoever the current user is at the given time)</p>

<p>I currently have:</p>

<ol>
<li>A .gs function Magic_Telling, that creates a modal dialog by using an HTML file</li>
<li>An HTML file, Prompt_Styling, that contains the css / html styling for the prompt. This HTML file then calls a .gs function All_In that processes the rows<br><br></li>
</ol>

<p>My code:</p>

<p><strong>Magic_Telling</strong>
Creates the modal dialog from HTML file.</p>

<pre><code>function Magic_Telling() {
var UI = SpreadsheetApp.getUi();
var newline = '\n'
// Display a modal dialog box with custom HtmlService content.
var htmlOutput = HtmlService.createHtmlOutputFromFile('PromptStyling')
    .setSandboxMode(HtmlService.SandboxMode.IFRAME)
    .setWidth(300)
    .setHeight(100);
UI.showModalDialog(htmlOutput, ' ');
}
</code></pre>

<p><br>
<strong>Prompt_Styling</strong> HTML file for styling prompt + script that runs the function All_In that will process rows</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
// some irrelevant stuff here
&lt;/head&gt;

&lt;script&gt;
window.onload = function() {    
google.script.run
    .withSuccessHandler(closeDialog)
    .All_In();
    };

window.closeDialog = function() {
    google.script.host.close();
    };

&lt;/script&gt;
&lt;/html&gt;
</code></pre>

<p><strong>All_In</strong> Function to process rows</p>

<pre><code>function All_In() {

UnlockRowBlocks();
UnhideRowBlocks();
LockRowBlocks();
HideRowBlocks();

}
</code></pre>

<p>When I run MagicTelling from the script editor, it works <em>beautifully</em>. The entire sequence executes (prompt shown, All_In executed, prompt disappeared). Perfect.</p>

<p>I then created an installable trigger by going to
    Script Editor > Resources > Current project's triggers
and added a trigger to run Magic_Telling every 3 hours.
(I presume this is an "installable trigger")</p>

<p>But I get this error message:</p>

<blockquote>
  <p>Cannot call SpreadsheetApp.getUi() from this context.</p>
</blockquote>

<p>...when the function reaches the first line of Magic_Telling</p>

<p>What should I do to get around this? </p>