Skip to content

8. How to write a script

corey.mac edited this page Nov 9, 2024 · 7 revisions

Steps

Prepare script information

When adding a script in Seer, it will read the variable SCRIPT_INFO first, and try to run the function script_info() if SCRIPT_INFO does not exist. It fails if neither exists or returns a dictionary type.

  • Required key: name, type, extensions, arguments
    • type has three values ​​to choose from
      • 0 : Preview
      • 1 : Controls
      • 2 : Property
    • extensions is a list of suffixes, list type, use ${type_folder} when you need to match folders
    • arguments are command line parameters, excluding python.exe and py file name
      SCRIPT_INFO = {
          "name": "unzip",
          "type": 1,
          "extensions": ["zip", "rar", "7z"],
          "arguments": ["-e", "${7z}", "-i", "${input_file}", "-o", __save_path, "-w"],
          # optional below
          "author": "Corey",
          "version": "1.0.1",
          "description": "unzip archive file here",
          # Controls only
          "icon_path": "icon.png",
      }

Write features

  1. Preview
    • Embedded type, OIT: The script displays a window, loads and parses the file, and sends a message to Seer after success, and Seer embeds the window into its preview window. Example parses ipynb type to html and displays using built-in browser.
    • Conversion type: load and parse the input file, and then save it as Seer's internal support type (such as PDF/image/HTML). The example converts an input file to HTML.
  2. Controls
    • After the preview is loaded successfully, Seer will display a button representing this function on the left side of the control bar, and the specified script will be executed after clicking. The example compresses the folder being previewed into a zip file and saves it to the current folder.
  3. Property
    • After the preview is successful, Seer will automatically call it. The script parses the input file, it saves the data to be displayed in the form of a json file to the specified location, and Seer reads the json file for display. Example for computing sha512 hashes of exe and dll files.

Variables

These will be replaced with real value, and sent to the script as arguments.

  • ${7z} the absolute path of 7z.exe which is distributed with Seer

    C:/Program Files (x86)/Seer/plugins/7z.exe

  • ${seer_exe} the absolute path of Seer.exe

    C:/Program Files (x86)/Seer/Seer.exe

  • ${seer_dir} where Seer.exe is located

    C:/Program Files (x86)/Seer/

  • ${input_file} the target file path, could be a file or a folder

    /file/to/the_preview_file

  • ${output_file} the location for output file: temp*folder + randomfilename***_without_extension**
    • when it's for Property, this value is needed
    • when it's for Preview, this value is needed when using script convert the unknown file format to a builtin format

      /path/to/temp_folder/random_str

  • ${oit} - Preview
    • used to tell Seer that it's using the embedded widget to preview
    • a flag for Seer, and will not be passed to the script as a command line argument
    • embed a foreign window into Seer: used in ipynb
  • ${no_cache} - Preview
    • used to tell Seer to delete the temporary files after the preview is closed
    • a flag for Seer, and will not be passed to the script as a command line argument
  • ${type_folder} - Controls only, for now
    • used to match folder type since it doesn't have a extension
  • ${use_backslash} use \ instead of /