Snippets

By providing complete command sequences that can be inserted in a script, the Packaging Workbench makes recurring tasks a lot easier. These command sequences are called snippets. Snippets can be created easily by selecting a command sequence from an eScript or Universal Script and then dragging & dropping this 'snippet' to the Snippet window.

For eScript snippets only:
When the eScript snippet is created, all of the contents you can change in the command dialog are automatically converted to variables. This allows the editor to customize these contents when inserting the snippet in an eScript later. When you create a snippet you can also define which of the variables contained in the snippet can be changed and which must remain. The files contained in the command sequence are also registered in the snippet and are stored in a separate folder.
As soon as the snippet is inserted, it is resolved to the actual command sequence and can be customized as usual in the eScript Editor. The files that are referenced in the command sequence are copied to the target script's package folder when the snippet is inserted.
This procedure ensures that a snippet can be used universally in different eScripts.

Some snippets automatically come with DSM (System Snippets) and some snippets are user-defined, they are either available to all DSMC users (Common Snippets) or they are only stored in an individual user's profile (My Snippets).

The snippets are stored in the following locations:

  • My Snippets:
    %USERPROFILE%\Documents\DSM\Snippets
  • Common Snippets:
    <DSM share>\Customization\Snippets
  • System Snippets (cannot be changed):
    <DSM share>\SSI\Snippets
  • You can specify individual child folders for Common Snippets or My Snippets.
    The snippets can only be edited if the user has the required file system permissions. The System Snippets cannot be changed in the Packaging Workbench. You can change the System Snippets with a text editor, however, this is not recommended.

Structure and Contents of Snippets

Generally, snippets are structured like eScripts or Universal  Scripts, they contain the same command sequences as these scripts do. There are a few differences between snippets and 'normal' scripts, however.

Note the following:

  • File name
    Snippets have the file extension *.snip, for example MySnippet.snip.
    Snippets for eScripts and Universal Scripts differ only internally in the Type (see below).
  • Contents
    The files with the extension snip contain more than just the command sequence; they also contain configuration settings, variable definitions and links to files that are contained in the command sequence.
    To make a clear difference, a snippet file is structured like an INI file and has the following sections [Config], [Variables], [Files] and [Script].

The individual sections of the snippet file have the following contents:

  • [Config]
    Contains general information on the snippet, e.g. the name and the unique tag.
    InsertstartStopMarker="1" ensures that a comment is added at the beginning and end of the command sequence when the snippet is inserted. This comment shows that the included command sequence comes from a snippet and also when the sequence was inserted. A comment is always added by default.
    InsertLabel="1" ensures that the correct label is automatically added at the beginning of the inserted snippet. The label is not added by default.
    Type="1" indicates that it is a snippet for eScripts.
    For Universal Scripts, the followig applies:
    Type="2": *.bat (DOS)
    Type="3": *.sh (Linux Shell)
    Type="4": *.vbs (Visual Basic)
    Type="5": *.cmd (WinPE)
  • [Variables]
    This section contains the variable definitions for the contents of the command dialogs that can be changed in the snippet. This includes texts, registry values, numerical values and links to external files, for example. Reappearing contents are replaced by the same variable.
    Links to files in the package folder are not listed in the [Variables] section but rather in the [Files] section.
    The variable syntax is as follows:
    [!]<VariableName>[,{String|Directory|File}][=<DefaultContent>]
    The String type is the default type if no variable type has been specified. Variables that are not supposed to be displayed as changeable when the snippet is inserted, are marked by a "!" in front.
  • [Files]
    Files that are referenced in the command sequence and that are in the package folder are stored in a folder that is named according to the name of the snippet file. The full path including the file name is specified in the [Files] section of the snippet file. External files contained in the command sequence (e.g. as a UNC path) are registered but not stored in the snippet folder.
    The syntax of the individual files is as follows:
    <File>="<RelativePathAndFilename>"
    Example:
    test.txt=".\Extern$\test.txt"

      The path of a file may also point to a folder that is used by several snippets at the same time. Note that you can only use these common folders by customizing them manually later.

  • [Script]
    This section contains the actual command sequence. You can only edit this sequence in the Extended Script Editor or by changing the snippet file manually.
  • The Extended Script Editor is solely used for editing the contents of the [Script] section. The usual editor commands are available for this task. You can edit the other sections of the snippet file with a 'normal' text editor.

    Note the following to make sure that the snippet works correctly after editing:
    When you change the snippet file manually, the changes to variables or files must be applied to both the [Variables] and/or the [Files] sections and also in the respective command in the [Script] section. Changes to the path and file name must also be applied to the file system, respectively.
    If you change snippet variables or snippet files in the Script Editor, note that these changes are not automatically applied to the [Variables] and [Files] section of the snippet file. If required, this must be done manually.

    When Universal Script snippets are created, they contain no sections for [Variables] and [Files]. But these can be added manually by editing the snippet using a text editor. This way, variables and files can also be used within Universal Script snippets.

Example of a Snippet

This snippet is employed to run a VB script which is contained in the snippet as a file. By means of a return value you set in the VB script before, a message is issued telling you whether the script was executed or not.

[Config]

Display="VBScript_Start"

Tag="{9FEDB56A-932A-45AC-BDEF-D44D7D3AD399}"

InsertStartStopMarker="1"

InsertLabel="0"

Type="1"

[Variables]

VBVariable="Start"

Var001="VB Script has been executed successfully."

Var002="VB Script could not be executed."

[Files]

eScript.vbs=".\Extern$\eScript.vbs"

[Script]

Set('VBVariable','%Snippet.VBVariable%')

CallScript('.\Extern$\eScript.vbs','')

If %VBVariable%='1'

MsgBox

%Snippet.Var001%

EndProc

Else

MsgBox

%Snippet.Var001%

EndProc