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.
$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.
$gameCount = $PlayniteApi.Database.Games.Count
$PlayniteApi.Dialogs.ShowMessage($gameCount)
Examples
Displays number of games in the game library when executing Show Game Count
menu from Extensions
menu.
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
}