Run script with 2 functions on document open

Ask questions about how to create a script or swap scripts with other users.
Post Reply
crtrubshaw
Posts: 250
Joined: 06 Jun 2012 11:08

Run script with 2 functions on document open

Post by crtrubshaw »

Hello, I would like to create a script which will run for each document I open and the 2 program functions I want to run are:

1. ConvertSpacesToTabsAction
2. RemoveTrailingSpacesAction

I can't do this as a macro because it forces me to stop recording and I can't find these functions anywhere in the documentation, does anybody know if this is possible?

Many thanks!

User avatar
pjj
Posts: 1784
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Run script with 2 functions on document open

Post by pjj »

If you never use tabs nor trailing spaces (and have your settings set accordingly) and just want to sanitize some docs, you could use a simplest script triggering editor to mark document as changed, to e.g. set caret at 1,1, add any character, delete it and then save document (or even change newline format and then revert it) -- and RJ TE will do the job for you. If not, take a look at Document.ReplaceAll() and ScriptUtils.RegExReplaceAll().
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus

crtrubshaw
Posts: 250
Joined: 06 Jun 2012 11:08

Re: Run script with 2 functions on document open

Post by crtrubshaw »

Good thinking pjj, thanks, all I needed was to run ScriptUtils.RegExReplaceAll() twice in the script and it did exactly what I wanted.

Cheers!

User avatar
pjj
Posts: 1784
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Run script with 2 functions on document open

Post by pjj »

Cheers! :-D

Image
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus

Post Reply