Clippings insert comments at top of script

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)

I can’t reproduce that here. Can you email me the clippings file in question?

Insert this clipping into an empty script.

[[*usescriptingadditions]]
[[*framework:Foundation]]
[[*library:Myriad Tables Lib]]
--modify table
modify table [[linked-template:theTable]]¬
	OK button name [[template:Text]] ¬
	OK button is default [[template:trueOrFalse]] ¬
	cancel button name [[template:Text]] ¬
	extra button name [[template:Text]] ¬
	grid style [[template:custompicker:grid_styling:grid none:grid between rows:grid between columns:grid between rows dashed:grid both:grid both dashed between rows]] ¬
	column widths pattern [[template:numberList]] ¬
	highlighted rows [[template:numberList]] ¬
	alternate backgrounds [[template:trueOrFalse]] ¬
	row dragging [[template:trueOrFalse]] ¬
	column reordering [[template:trueOrFalse]] ¬
	accessory view [[template:Any]] ¬
	hidden cancel button [[template:trueOrFalse]] ¬
	initial position [[template:numberList]]

Thanks. Does it fail in case other than a completely empty document?

Not sure. I’ll try it

It also happens if you paste it into a document where the only other content is a commented line.

I’ll see if there are any other cases.

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.

I’m going to remove the unnecessary blank lines that get removed, but I’m inclined to leave the comment behavior as it is.

1 Like