Show / Hide Table of Contents

Playnite Scripting Introduction

Basics

Playnite can be extended with additional functionality using scripts. PowerShell and IronPython languages are supported.

Note

PowerShell support requires at least PowerShell 5.0 to be installed. If you are Windows 7 user you need to install it manually (Windows 8 and 10 includes it by default).

Creating script extensions

Run Toolbox with arguments specific to a type of script you want to create.

For example, to create new PowerShell script extension:

Toolbox.exe new PowerShellScript "Some script" "d:\somefolder"

Accessing Playnite API

Playnite API is available to scripts via PlayniteAPI variable. Variable provides IPlayniteAPI methods and interfaces. For example to get list of all games in library use Database property from IPlayniteAPI and Games collection.

  • PowerShell
  • IronPython
$PlayniteAPI.Database.Games
PlayniteApi.Database.Games

To display number of games use Dialogs property from PlayniteApi variable. Dialogs provides IDialogsFactory interface containing method for interaction with user. ShowMessage method will show simple text message to user.

  • PowerShell
  • IronPython
$gameCount = $PlayniteApi.Database.Games.Count
$PlayniteApi.Dialogs.ShowMessage($gameCount)
game_count = PlayniteApi.Database.Games.Count
PlayniteApi.Dialogs.ShowMessage(str(game_count))

Examples

Displays number of games in the game library when executing Show Game Count menu from Extensions menu.

  • PowerShell
  • IronPython
function global:DisplayGameCount()
{
    $gameCount = $PlayniteApi.Database.Games.Count
    $PlayniteApi.Dialogs.ShowMessage($gameCount)
}

function global:GetMainMenuItems()
{
    param($menuArgs)

    $menuItem = New-Object Playnite.SDK.Plugins.ScriptMainMenuItem
    $menuItem.Description = "Show Game Count"
    $menuItem.FunctionName = "DisplayGameCount"
    $menuItem.MenuSection = "@"
    return $menuItem
}
from Playnite.SDK.Plugins import ScriptMainMenuItem

def display_game_count():
    game_count = PlayniteApi.Database.Games.Count
    PlayniteApi.Dialogs.ShowMessage(str(game_count))

def get_mainmenu_items(menu_args):
    menu_item = ScriptMainMenuItem()
    menu_item.Description = "Show Game Count"
    menu_item.FunctionName = "display_game_count"
    menu_item.MenuSection = "@"
    yield menu_item    
  • Improve this Doc
Back to top Generated by DocFX