I have a bunch of clippings like this, where they insert a command into a script, and make sure the script has use scripting additions and use script at the top.
I also have a commented line that describes the command being inserted. The problem is that the comment always gets inserted at the very top of the script, instead of with the command where it should be.
I noticed that if it’s just one of the directives it works. It would be great if there were a way to keep the comments where they belong.
[[*usescriptingadditions]]
[[*library:filemanagerlib]]
--Change modification date
change value for [[template:Any]] ¬
to [[template:Any]] ¬
property name modification property
→ Script Debugger 8.0.4 (8A50)
→ Mac OS 11.6.3 (20G415)
So the issue is this. For various reasons, the insertion of use lines is done last. If there’s an existing use statement of some other kind, it goes after the last one. If there’s a -- classes, constants, and enums used line, it goes before that. If there’s a property statement, it goes before that. Otherwise it goes before the first non-commented line, on the assumption that the first comment in a script is normally related to the script itself.
Obviously this assumption isn’t always true. But I suspect it’s a better assumption than the opposite, which is the only other choice. I can probably change the behavior for a completely empty document, but not otherwise.
So my question is: if you’re regularly using snippets with use statements, why would you use a completely blank template to start with?
That’s a good question. In the past my templates were always blank to start, but lately they’ve had use appleScript and use scripting additions statements.
I think I probably see the behavior mostly when I’m working on clippings, not when I’m working on scripts.