Since templates were discontinued I've been using this AppleScript to make a quick HTML doc:
#!/usr/bin/osascript tell application "System Events" keystroke "p" using {control down, option down, shift down} keystroke "4" "<!DOCTYPE html> <html lang="da"> <head> <meta charset="utf-8"> <title>$1</title> <meta name="description" content=""> <style type="text/css" media="screen"> *{margin:0;padding:0;} $2 </style> </head> <body> $0 </body> </html>" end tell
It’s been working fine until now. I’m on beta.11.8, and I’m very sorry, but I don’t know if the problem arose with this update or one of the ones from last week.
The problem is rather unusual. It appears that System Events is reversing the order of the commands.
Instead of simulating the keyboard shortcut for selecting PHP, all of the template is inserted via keyboard simulation, then 4 for PHP is pressed and only THEN the shortcut is pressed. But it doesn’t go back to working, if I reverse the sequence in the command code.
This is what it looks like:
Resultat
Here are the settings for the command:
Settings
Rasmus
On Jul 12, 2016, at 1:37 PM, Rasmus Malver rasmus@malver.dk wrote:
Since templates were discontinued I've been using this AppleScript to make a quick HTML doc:
I'm kind of amazed your script _ever_ worked. You're not even talking to TextMate. And I don't see anything that would make the template text appear in the document; you're just making a kind of "here doc". You're just sort of trusting that the "result" of your script will magically become the text of the document at the right moment.
m.
-- matt neuburg, phd = http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 9! http://shop.oreilly.com/product/0636920044352.do iOS 9 Fundamentals! http://shop.oreilly.com/product/0636920044345.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
On Jul 12, 2016, at 2:43 PM, Matt Neuburg matt@tidbits.com wrote:
I'm kind of amazed your script _ever_ worked. You're not even talking to TextMate. And I don't see anything that would make the template text appear in the document; you're just making a kind of "here doc". You're just sort of trusting that the "result" of your script will magically become the text of the document at the right moment.
Just to be more specific, here's an AppleScript that does more the sort of thing you're after:
tell application "System Events" tell application "TextMate" to activate tell application process "TextMate" keystroke "n" using {command down} delay 1 keystroke "h" using {control down, option down, shift down} delay 1 keystroke "1" delay 1 keystroke "<html>" keystroke return keystroke "</html>" end tell end tell
That's not the exact result you're after, but it is the sort of thing you should be doing. m.
-- matt neuburg, phd = http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 9! http://shop.oreilly.com/product/0636920044352.do iOS 9 Fundamentals! http://shop.oreilly.com/product/0636920044345.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
Yup. It's not even my script or idea. When TextMate discontinued new-from-template I wrote to this very list, and that script was the solution provided.
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"> … |
Allan, I'm chuffed there's finally a way to set the language without resorting to the AppleScript tell System Events-thing! I'll look into it tomorrow!
Thanks,
Rasmus
On 12/07/16 23.43, Matt Neuburg wrote:
On Jul 12, 2016, at 1:37 PM, Rasmus Malver rasmus@malver.dk wrote:
Since templates were discontinued I've been using this AppleScript to make a quick HTML doc:
I'm kind of amazed your script _ever_ worked. You're not even talking to TextMate. And I don't see anything that would make the template text appear in the document; you're just making a kind of "here doc". You're just sort of trusting that the "result" of your script will magically become the text of the document at the right moment.
m.
-- matt neuburg, phd = http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 9! http://shop.oreilly.com/product/0636920044352.do iOS 9 Fundamentals! http://shop.oreilly.com/product/0636920044345.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
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/26e66b887a96b8062d86461cd97a561e...).
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.