[TxMt] Re: AppleScript template not working

Allan Odgaard mailinglist at textmate.org
Tue Jul 12 21:43:15 UTC 2016


On 12 Jul 2016, at 22:37, Rasmus Malver wrote:

> Since templates were discontinued I've been using this AppleScript to
> make a quick HTML doc:

I suggest you change the command to a snippet with your desired 
boilerplate.

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:

	<!DOCTYPE html>`"$TM_MATE" &>/dev/null -t text.html.php &`
	<html lang="da">
	…

When inserted, it should change document type to `text.html.php`.

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:

1. Go to Bundles → HTML → Language Grammars → HTML and clear the 
First Line Match text field.

2. Go to Bundles → PHP → Language Grammars → PHP and change the 
First Line Match to this:

		^#!.*(?<!-)php[0-9]{0,1}\b|<\?php|<!DOCTYPE html>

Now when the first line of a document contains `<!DOCTYPE html>` 
TextMate will change type to PHP, this inclundes inserting your HTML 
boilerplate in a new untitled document.

> […] The problem is rather unusual. It appears that System Events is
> reversing the order of the commands.

It was likely caused by 
[26e66b8](https://github.com/textmate/textmate/commit/26e66b887a96b8062d86461cd97a561e9d4b0c72).

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).

So I hope one of the two approaches suggested above will be acceptable 
solutions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20160712/99c99471/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2016-07-12 at 22.09.54.png
Type: image/png
Size: 55470 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20160712/99c99471/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2016-07-12 at 22.24.13.png
Type: image/png
Size: 51316 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20160712/99c99471/attachment-0003.png>


More information about the textmate mailing list