Run scripts on events
My previous request was to remove trailing whitespace from text when the document is saved. I implemented the feature using a simple applescript to apply a regular expression replace to the document, but then I realized how great it would be for my script to be called whenever my document was manually saved.
Thinking more abstractly, it would be really cool if we could associate scripts not only with hotkeys but also with events.
Some event examples:
- before_save
- after_save
- on_keypress
- on_keydown
- on_keyup
- on_change
- on_load
Implementation suggestion:
- add one script to the script folder named events.config or events.json in which you can associate events to scripts
- add "hooks" in the code to fire events
- add an event handler function to call the associated scripts for the specific event.
Does this sound like a good idea to anyone else?
I've thought so for a long time how I can implement such script callback on CotEditor and it's still pending. It is definitely true that this feature makes a lot of users incl. me happy.
Your approach seems in some respects good. Though there are some another blockers to be resolved in order to realize this feature, I'll gradually make a start on it.
Have hotkeys for scripts been implemented? Can't find any info.
@ricardobeat You can set shortcut keys for scripts adding specific characters to the script file name. For details, see "File naming rules for CotEditor scripts" page in CotEditor's help. You can reach to the help page from the main menu > Help.