Create a 'service' in Automator.
Give it the following settings:
Service receives 'no input' in 'any application'
Check 'Output replaces selected text'
Add the following 'Actions'
Get Specified Text - insert your clip here
Copy to Clipboard
Run AppleScript - replace the (* your script *) with 'the clipboard'
Click the 'Run' button to test the workflow. If there are no issues here, save the service.
To test whether the service works, put the cursor in a text doc of some sort (any place that you can paste multi-line text) and right-click… you should see the service's name in the menu. Click it and see what happens. Hopefully, it will paste your clipping into the text area which the cursor is in.
If it works well, go to the System Preferences > Keyboard > Shortcuts and click Services. Scroll through the resulting list on the right to find the name of your newly created service (should be in the Text section). Give it a keyboard shortcut (hopefully one that doesn't conflict with any other), and you're done.
So what does the service do? You specify the text for the clipping, it copies that to the clipboard. The applescript pastes the clipboard wherever you trigger the service.
As an aside, you don't mention what text editor you're using which might make it easier to devise a solution. BBedit was mentioned in the comments but the are other apps such as Coda that also offer some variation of a clippings feature. And as a further aside, I am unable to include a screenshot with my post.
\"topic-title\"
. You could do something like, e.g.set the clipboard to "<li>" & linefeed & "<div class=\"topic-title\">" & linefeed & "<h2>Topic title goes here</h2>" & linefeed & "</div>" & linefeed & "</li>"
then activate the target app, then use System Events to paste it, e.g.:tell application "System Events" to keystroke "v" using command down
paste
command instead of System Events. Or you could just set up a text replacement where you'd type something and it would be replaced with the HTML code. System Preferences > Keyboard > Textcmd
and it get replaced with_command_
and shows as command. Almost everything I write more than a few times I've setup a text replacement for. You could use e.g.topt
and have it replaced with the HTML code in your OP