PrimalScript adds Custom PrimalSense (Part 3: Cached and dynamic data lists)
With the latest service build (7.1.67) of PrimalScript 2015 we introduced a new feature; custom PrimalSense. In the first part of this series we showed you how to create a simple list and what options you have for providing data for these lists. In the second part we showed you how to make these lists multi-select and how to add images to your items. If you missed the previous posts, click here for part 1 and here for part 2.
Some if the information you want to display in a PrimalSense list is not static. It can change dynamically from day to day or even every second. In order to enable you to display such ever changing information we added a mechanism to create the data on the fly by an external process. While we will use Powershell in our examples here, this is not limited to PowerShell. You can use any programming or scripting language, command line or windows tool that you can make generate the previously described data files in either CSV or XML format.
Let us start with an example for a cached list. A cached list will only execute the associated process once per session. This is useful for data that may take a little longer to generate but does not change all the time. A list of available Powershell modules is a good example. The list can change, but usually changes will only occur upon installation system updates or additional software.
Most of the items in this INI file will be familiar from the last post.
Name is the identifier for the list.
Multiselect determines if the list is single select (0) or multi-select (1).
Imagelist provides a bitmap for a custom image list.
Type specifies the type of list. Possible values are “static”, “cached” or “dynamic”.
Here are the new items that apply to this sample:
Timeout specifies the amount of time PrimalScript will wait for a process to finish in milliseconds. The default value is 2000 (2 seconds).
if a process does not finish within the specified amount of time, PrimalScript will use data from a previous session if available or simply do nothing if there is no data.
As PrimalScript has to wait for the process to finish make sure you understand that a long running task will block PrimalScript until the process ends or the timeout expires.
Process specifies the process to run to generate the data for the list.
Datafile is the name of the generated data file. If you just specify the file name, the file is assumed to be created either in the lists folder or in the folder the currently active script exists in. You can specify a fully qualified file name if the data has to be pulled from a central location.
The second example we show you today is for a dynamic list. The process associated with this will launch every single time you launch the list.
The file list shows the files contained in the same folder as the currently active script. Note the changed type to “dynamic” and of course the different process.
As a side note, if you need to run an elevated process you can use the “elevated” keyword instead of “process”. Since this usually prompts for confirmation the timeout may be getting in your way. It is usually best to avoid using elevated commands for generating dynamic lists.
As you can see, making dynamic lists is just as simple as static lists. As a little exercise, take the file list example and make a “script” list that only displays *.ps1 files.
If you have any questions, comments or suggestions, please feel free to go the PrimalScript forum and post what is on your mind.