top of page

Playnite Scripting


Playnite
Playnite

A quick guide to Playnite scripting. One of the advantages of running with Playnite is the ability to run scripts before a game starts, after a game starts and after quitting a game.


This means that HOTAS profiles can be loaded or cd images mounted before a game starts and then closed or unmounted once a game has been quit. Starting a game now becomes a one button click instead of having to preconfigure various utilities before you can play.


Playnite currently supports PowerShell 5.1 scripts, installed on Windows 10 machines by default.


We'll take a look at a couple of uses and then a complete example with Joint Strike Fighter (JSF).


HOTAS profiles


TARGETGUI is the app used to load profiles for my TM Warthog HOTAS. Depending on your HOTAS supplier you may have to use a different profiling app.


Loading a profile


Loading a HOTAS profile will depend on your suppliers software. In this example Thrustmaster TARGET will be used.


The Start-Process command runs an executable, it has two arguments, the -filepath argument which specifies the full file path to the executable and the -ArgumentList parameter which specifies the arguments to pass to the executable.


As the file path argument contains spaces the file path is surrounded by " (double quotes). The ArgumentList parameter contains a file path to the HOTAS profile (surrounded with double quotes). As the HOTAS profile file path uses double quotes the ArgumentList must use ' (single quotes) to surround all of the arguments, ass shown below:


Start-Process -FilePath "C:\Program Files (x86)\Thrustmaster\TARGET\x64\TARGETGUI.exe" -ArgumentList '-r "D:\Games\Dos\Falcon Gold\conf\Advanced.fcf"'

Start-Sleep -Seconds 5

As this is for the DOSBox emulated game, Falcon Gold, the HOTAS profile sits in the D:\Games\Dos\Falcon Gold\conf folder.


As this app can take a few seconds to start and load a profile, we want to make sure it is fully loaded before starting the game.


The Start-Sleep command allows the script to pause for 5 seconds before starting the game, ensuring the HOTAS profile is loaded.


Unloading a profile


When we quit a game we want to unload the profile, so we can run another game that may use a different profile. We do this by closing the TARGETGUI process that was started earlier, with the following command:


Stop-Process -Name "TARGETGUI"

Cd images


A cd mounting app that supports running from the command line is required for scripting purposes. Some examples include WinCDEmu and Daemon Tools Lite.


Mounting cd images


Again the Start-Process command is used with an argument list. WinCDEmu uses the batchmnt command:


Start-Process -FilePath "C:\Program Files (x86)\WinCDEmu\batchmnt" -ArgumentList "D:\Games\jsf setup\Joint Strike Fighter.cue"

No need for single quotes around the ArgumentList this time as there is only a single argument which is the cd image.


Daemon Tools Lite uses the DTCommandLine command:


Start-Process -FilePath "C:\Program Files\DAEMON Tools Lite\DTCommandLine.exe" -ArgumentList '--mount --ro --path "D:\Games\jsf setup\Joint Strike Fighter.cue"'

Double quotes surrounds the file path (with spaces) argument, which means single quotes surround the whole argument list.


Unmounting cd images


When quitting a game the cd image should be unmounted to leave your system in a clean state ready to mount another cd image from another Paynite script should the game require it.


To unmount we just need to run the same commands again but with the unmount option present. For WinCDEmu we use batchmnt again:


Start-Process -FilePath "C:\Program Files (x86)\WinCDEmu\batchmnt" -ArgumentList '-umount "D:\Games\jsf setup\Joint Strike Fighter.cue"'

And we use the DTCommandLine command again for Daemon Tools Lite:


Start-Process -FilePath "C:\Program Files\DAEMON Tools Lite\DTCommandLine.exe" -ArgumentList '--remove_all'

Putting it all together


In this example used for Joint Strike Fighter (JSF) a script is run before starting a game to mount a cd image with WinCDEmu and start a TARGET profile.


Start-Process -FilePath "C:\Program Files (x86)\WinCDEmu\batchmnt" -ArgumentList "D:\Games\jsf setup\Joint Strike Fighter (Europe).cue"
Start-Process -FilePath "C:\Program Files (x86)\Thrustmaster\TARGET\x64\TARGETGUI.exe" -ArgumentList '-r "D:\Games\jsf setup\conf\JSF.fcf"'
Start-Sleep -Seconds 5

After quitting the game the following script is run to close the TARGET profile and unmount the cd image.


Stop-Process -Name "TARGETGUI"
Start-Process -FilePath "C:\Program Files (x86)\WinCDEmu\batchmnt" -ArgumentList '-umount "D:\Games\jsf setup\Joint Strike Fighter (Europe).cue"'

These scripts are added to the relevant section in the Scripts tab of the Edit Game Details dialog in Playnite, as shown below:


Playnite Scripts tab
Playnite Scripts tab

Further information


The following may provide further useful information:



To see a list of TARGETGUI command line options, run the following from a command line:

"c:\Program Files (x86)\Thrustmaster\TARGET\x64\TARGETGUI" -help

This assumes TARGET is installed in the default installation folder.

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating

Drop Me a Line, Let Me Know What You Think

Thanks for submitting!

© 2035 by Train of Thoughts. Powered and secured by Wix

bottom of page