Yes i do it the same way:

#title = "Enclose selection";
#tooltip = "Enclose an selection with an sign";
// Select some text and execute this macro to put an sign
// in front and at the end of the selected text;

//mySign = "\%"
mySign = prompt( "Enter sign to enclose selection:", "\%" );

selText = document.selection.Text;
outText = mySign + selText + mySign;

document.selection.Text = outText;

Should be easy to modify this code
and replace mySign with LeadingSign and TrailingSign :-)