Commands

From Ketarin
Revision as of 20:16, 12 October 2010 by Floele (talk | contribs) (Batch scripts)

Many actions can be defined using Ketarin's user interface. Some advanced behaviours require custom scripts though.

Command types

Pre-update commands

In the “Commands” tab of each application and in the settings of Ketarin you can enter a command which is to be executed before every update. "Before update" means before it is attempted to download, when an update has been found. You can decide to abort the download at this point, by exiting the script with exit code 1 ("exit 1" when using a batch script) or to skip downloading with exit code 2 (since version 1.5).

Post-update commands

In the “Commands” tab of each application and in the settings of Ketarin you can enter a command which is to be executed after every update. This is useful for unzipping ZIP packages, virus scans, installations in background and other purposes.

Post-update all command

In the settings of Ketarin you can define a command that is executed after all applications have been updated, for example to execute cleanup tasks or sync the results to another location.

Execution order

The commands that can be entered are executed in the following order:

  1. Default pre-update command in settings
  2. Application specific pre-update command
  3. Download of update
  4. Default post-update command in settings
  5. Application specific post-update command
  6. Command to execute after updating all applications

Script types

Ketarin supports Batch scripts and C# scripts. Below every text box in which you can enter a script is a button which lets you choose the script type.

Batch scripts

Batch scripts are simple and useful. They allow you to execute any command you would usually execute on command line. Typical possibilities are renaming, copying and deleting files.

By default, Ketarin waits for the script to be finished before proceeding with the next step. If you do not like that, you can put an ”&” at the very end of the script to execute it in background. You can also temporarily disable a line in the script by adding “rem ” at the beginning.

Command Task
7z x "{file}" -o"{root}PATH\" -y Extract the downloaded file to a given path on the drive where Ketarin.exe is located (7zip required)
7z x "{file}" -o"{root}PATH\" *.exe *.dll -r -y Extract the specified file types from the downloaded file to a given path on the drive where Ketarin.exe is located (7zip required)
7z e "{file}" -o"{root}PATH\" -y Extract the downloaded file to a given path on the drive where Ketarin.exe is located; flat, not preserving the directory structure (7zip required)
7z x "{file}" -o%temp% *.exe -r Extract the specified file types from the downloaded file to the temp directory (7zip required)
...\UniExtract.exe "{file}" "{root}PATH\" Extract the downloaded file to a given path on the drive where Ketarin.exe is located, using UniExtract
start "" /wait ...\UniExtract.exe "{file}" %temp% Extract the downloaded file to to the temp directory, using UniExtract
copy /y %temp%\*.exe "{root}PATH" Copy files of the selected type from the temp directory to a path on the drive where Ketarin.exe is located
robocopy %temp% "{root}PATH" *.exe /e /b /np Copy files of the selected type from the temp directory to a path on the drive where Ketarin.exe is located, using Robocopy
ren "{file}" ABC.msi Rename a file (with wildcard support)
del "{file}" /s /q Delete a file
rd "PATH" /s /q Delete a folder
start "" /wait COMMAND Start a command and wait until it finishes
nircmd elevate cmd /c copy /y "{file}" "%ProgramFiles%" Copy a file with elevated privileges, requires nircmd
nircmd elevate cmd /c Start an elevated command prompt, requires nircmd
nircmd shortcut "%ProgramFiles%\procexp.exe" "~$folder.desktop$" "{appname}" Create a shortcut to a file on the desktop, requires nircmd

C# scripts

Additional to Batch scripts you can also create C# scripts. C# can be considered much more powerful than Batch, and you can also directly access the internal data structure of Ketarin. If you know C# (numerous tutorials available on the internet), you can write scripts which perform any actions you like. For simplicity, you do not have to define classes or functions, just the code.

Snippets

Using the Command button, you can also save and open code snippets. You can create snippets for many generic commands so you won't have to copy/write them again every time.

  • Inser snippet - Insert a custom saved snippet at the current cursor position (select a snippet from the dropdown menu).
  • Save as - Saves the currently selected text (or the contents of the text area if none is selected) as snippet. You can save as new or overwrite an existing one.
  • Delete snippet - Delete a snippet (select a snippet from the dropdown menu).