# Startup scripts

When new editor window is launched (but before the document is loaded or created), file `init.qs` from application's data directory is run, then file `userinit.qs` from users's application configuration directory (which is `$HOME/.pdfedit`) is run, if it exists This is in default configuration and it can be changed by user to different filename(s) in settings . These files should contain declaration of all functions used in toolbars or menus and may also contain any startup code to be run before loading or creating new document.

In commandline mode, file `init_console.qs` from application's data directory is run instead, then file `userinit_console.qs` from users's application configuration directory (which is `$HOME/.pdfedit`) is run, if it exists

After running these init scripts, any "plugin" scripts from directories specified in configuration are run. By default, these directories are:

1. Directory `scripts` in application's data directory

2. Directory `scripts` in application's binary directory

3. Directory `./pdfedit/scripts` in user's home directory

For "plugin scripts" in commandline mode, scripts are searched in `console` subdirectory of above directories instead.

Scripts are run in alphabetical order (by their filename, case sensitive) and if the same script is encountered in more than one directory, only the one in directory later in list is executed. This ensures that if user install newer version of some script in his home directory, only his version will get executed.

After that, the document is loaded (if it was not specified on commandline, the window will be initially empty without any document)

Init script should not load a document while starting, as it will be replaced by new one as soon as the script finishes. If functionality such as "automatic loading of a document on startup" is desired, appropriate code should be added to onEmptyFile() function, which will be triggered after starting the editor with empty document. Alternatively, onLoad, onLoadUser or onLoadError fnuctions may be used for this.