<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8">
</head>
<body>
<div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">On 12 Jul 2016, at 22:37, Rasmus Malver wrote:</p>

<p dir="auto"></p></div>
<div style="white-space:pre-wrap"><blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px"><div dir="auto">Since templates were discontinued I've been using this AppleScript to
</div><div dir="auto">make a quick HTML doc:
</div></blockquote></div>
<div style="white-space:normal">

<p dir="auto">I suggest you change the command to a snippet with your desired boilerplate.</p>

<p dir="auto">In this snippet you can use backticks to execute commands and then use TM_MATE to set the language of the current document, for example make the snippet like this:</p>

<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7"><!DOCTYPE html>`"$TM_MATE" &>/dev/null -t text.html.php &`
<html lang="da">

</code></pre>

<p dir="auto">When inserted, it should change document type to <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">text.html.php</code>.</p>

<p dir="auto">Another more declarative approach is via the PHP grammar’s first line match, though as your first line is currently matched by the HTML grammar, you need to make two changes:</p>

<ol>
<li value="1"><p dir="auto">Go to Bundles → HTML → Language Grammars → HTML and clear the First Line Match text field.</p></li>
<li value="2"><p dir="auto">Go to Bundles → PHP → Language Grammars → PHP and change the First Line Match to this:</p>

<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7">^#!.*(?<!-)php[0-9]{0,1}\b|<\?php|<!DOCTYPE html>
</code></pre></li>
</ol>

<p dir="auto">Now when the first line of a document contains <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7"><!DOCTYPE html></code> TextMate will change type to PHP, this inclundes inserting your HTML boilerplate in a new untitled document.</p>

<p dir="auto"></p></div>
<div style="white-space:pre-wrap"><blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px"><div dir="auto">[…] The problem is rather unusual. It appears that System Events is
</div><div dir="auto">reversing the order of the commands.
</div></blockquote></div>
<div style="white-space:normal">

<p dir="auto">It was likely caused by <a href="https://github.com/textmate/textmate/commit/26e66b887a96b8062d86461cd97a561e9d4b0c72" style="color:#3983C4">26e66b8</a>.</p>

<p dir="auto">This change was made to fix another issue, it won’t be the last change related to synchronous command execution, but I am not sure TextMate should guarantee anything about the order in which things are done when running a command which produce output and send key strokes to TextMate (while running).</p>

<p dir="auto">So I hope one of the two approaches suggested above will be acceptable solutions.</p>
</div>
</div>
</body>
</html>