Playnite Forums
  • Playnite Web
  • Rules
  • Members
  • Team
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Playnite Forums Playnite Support and Troubleshooting Powershell extension not shown in menu

Powershell extension not shown in menu
mbeemer
Offline

#1
03-22-2022, 12:02 PM
I am a PowerShell novice, but have successfully managed to update the Library Exporter script to add columns and such (and I was so proud of myself!)

I have attempted to mirror the elements of that script extension to create a new one to programmatically update a single game entry, to test the process so I can create some batch updates.

1. I have a folder in my Extensions directory - Apply_Updates
2. The folder contains the files - extension.yaml, ApplyUpdates.psm1
3. extension.yaml contains the following entries:

Id: Apply_Updates
Name: Apply Updates
Author: Playnite
Version: 1.0
Module: ApplyUpdates.psm1
Type: Script

4. ApplyUpdates.psm1 contains the following:

function global:ApplyUpdates()
{
    $game = $PlayniteApi.Database.Games["<game id>"]
    $game.Notes = "<note text>"
    $PlayniteApi.Database.Games.Update($game)
}

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

    $menuItem = New-Object Playnite.SDK.Plugins.ScriptMainMenuItem
    $menuItem.Description = "Apply Updates"
    $menuItem.FunctionName = "ApplyUpdates"
    $menuItem.MenuSection = "@"
    return $menuItem
}

5. I previously received alerts on starting Playnite that the script was not loaded due to an unspecified error, and managed to eliminate that by correcting some syntax errors.
6. The script now loads without complaint, and appears as installed and enabled in the Add-Ons/Generic dialog.
7. "Apply Updates" does not appear in the "Extensions" menu.

I have checked other scripts and experimented with replacing '$menuArgs' with '$getMainMenuItemsArgs' but I get the same result.

Can you tell me what I am doing wrong?  Should I be looking for any tab characters and replace them with spaces, for instance?
Jeshibu
Offline

Super Moderator
#2
03-22-2022, 12:21 PM
I think it's expecting an array out of GetMainMenuItems, so try this:

return @($menuItem)
mbeemer
Offline

#3
03-22-2022, 12:25 PM
(03-22-2022, 12:21 PM)Jeshibu Wrote: I think it's expecting an array out of GetMainMenuItems, so try this:

return @($menuItem)

No joy, but thanks for helping so quickly!
Crow
Offline

Administrator
#4
03-22-2022, 12:27 PM
Your function definitions are "global", which is wrong:
https://playnite.link/docs/master/tutori...pting.html
mbeemer
Offline

#5
03-22-2022, 01:04 PM
(03-22-2022, 12:27 PM)Crow Wrote: Your function definitions are "global", which is wrong:
https://playnite.link/docs/master/tutori...pting.html

Thank you very kindly!  I apparently copied from an obsolete version of the LibraryExporter extension.

Ahhhh...  Now the item appears in the menu, but selecting it results in "Failed to execute menu action.  A positional parameter cannot be found that accepts argument 'Playnite.SDK.Plugins.ScriptMainMenuItemActionArgs'."


And now it appears that my graphics card has died, so it may take me some time to try the next suggestions.

Thanks for the help!
mbeemer
Offline

#6
03-23-2022, 09:32 AM
Again the cause is copying from an obsolete script. Added

param(
$scriptMainMenuItemActionArgs
)

to the ApplyUpdates function and all is well. Thanks for your help and patience!
mbeemer
Offline

#7
03-23-2022, 10:12 PM
A bit of experimenting with PowerShell and I have my desired result:

function ApplyUpdates()
{
param(
$scriptMainMenuItemActionArgs
)

$Datatable = New-Object System.Data.DataTable

## By Default Import-csv uses first row as Header
$csvall = Import-Csv -Path "D:\Playnite Updates.csv"

$csvheaders = $csvall | Get-member -MemberType NoteProperty

Foreach ($header in $csvheaders) {
$Datatable.Columns.Add($header.Name)
}

Foreach($csv in $csvall) {
$row = $Datatable.NewRow()
$row.Name = $csv.Name
$row.Id = $csv.Id
$row.PurchaseDate = $csv.PurchaseDate
$row.Notes = $csv.Notes

$Datatable.Rows.Add($row)
}

Foreach ($row in $Datatable.Rows) {
$game = $PlayniteApi.Database.Games[$row.Id]
$game.Name = $row.Name
$game.Added = $row.PurchaseDate
$game.Notes = $row.Notes
$PlayniteApi.Database.Games.Update($game)
}

}

function GetMainMenuItems()
{
param(
$menuArgs
)

$menuItem = New-Object Playnite.SDK.Plugins.ScriptMainMenuItem
$menuItem.Description = "Apply Updates"
$menuItem.FunctionName = "ApplyUpdates"
$menuItem.MenuSection = "@"
return $menuItem
}

I expect I could transcribe values directly from the csv object, but baby steps...
mbeemer
Offline

#8
03-24-2022, 02:33 PM
(03-23-2022, 10:12 PM)mbeemer Wrote: I expect I could transcribe values directly from the csv object, but baby steps...

(And I did.)
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode