-
PowerShell's Read Line
10/11/2022 at 02:18 • 0 commentsSo, after the last project log, it looks like I will have to backtrack to WPF/winforms.
So now, I'm spending my time looking for a syntax highlighter for powershell. For the most part I have been successful.
It looks like the only good ones out there are the ones used by Microsoft. Luckily, at least one of these "highlighters" is open source: PSReadLine.
PSReadLine is a ReadLine parser for PowerShell, and comes included with most instances of PowerShell. It provides a variety of handy features, such as text completion, shell history, and most importantly syntax highlighting.
While I did not make a lot of progress today, I'm hoping my research into PSReadLine will be time well spent
-
Move from XAML to Web-Tech
10/10/2022 at 04:17 • 4 commentsOriginally, I thought I was locked down to PowerShell's access to C# and XAML, but with WebView2, I can now use my knowledge of Web Dev, to get this moving faster, except... that WebView2 currently has no support for linux :(
But Photino does! For now, we will write the app using Photino, but backtrack to WebView2 progressively to keep this app MS-purist (keeps the code enterprise-friedly)
I had to make this move, because I could not find any good syntax highlighters for WPF. However, I know of plenty written for HTML.
In terms of performance, going to web tech seems like a down grade, but Edge Chromium is supposed to be extremely performant, and Photino claims to be more performant than Edge!
Hopefully, this will be a "profitable" move -if only I were making money doing this :(
-
QuickTray UI Concept
10/09/2022 at 21:16 • 4 commentsSo, I want the UI to mimic the default PowerShell App for the platform. Since, we are currently only designing the menu for Windows PowerShell The GUI will look like it was pulled straight from that application.
Here is the working draft:
Eventually on Linux...
I want to have the UI blackened for Ubuntu. I want to also see, if I can implement a detection script that checks for Windows Terminal, and matches the theme.
-
WPF/XAML-based Context Menu - Part 1: NotifyIcon
10/09/2022 at 17:54 • 0 commentsThe code for this project is gonna be based on the notification app made by Trevor Jones on his blog SMSAgent.
The first thing that needs to be done is to give PowerShell support for XAML (PresentationFramework) and NotifyIcon/ApplicationContext (System.Windows.Forms):
Add-Type –AssemblyName System.Windows.Forms,PresentationFrameworkTo learn more about Application Context and what it does in C#, take a look at this article on creating C# Splash Screens.
We will use Application Context to keep the script running, and prevent NotifyIcon artifacts (If we don't run an application context, notifyicon may persist to run even once the powershell script exits)
To create the App Context, initiate it as an object (we will invoke the .run() method at the end of the script):
$appContext = New-Object System.Windows.Forms.ApplicationContext
In Trevor Jones's article, he used a Base64 string to create the notification tray icon. An alternative to this is to extract one from a preexisting favicon. To do that we'll pull the method used by Damien Van Robaeys in his article on PowerShell Systray applications:
$executable = "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe" $icon = [System.Drawing.Icon]::ExtractAssociatedIcon( $executable )
**if needed add System.Drawing to the Add-Type command, if it is missing
Here, we pull the icon from Windows PowerShell. Don't have to maintain an icon for the app, if we just pull a pre-existing one, right?
Now, let's create the systray icon:
$QuickTray = New-Object System.Windows.Forms.NotifyIcon $QuickTray.Icon = $icon $QuickTray.Text = "PowerShell Quick Tray"
In Trevor's article, he created the systray icon under the "$Script:" scope, but since this app is gonna serve as a powershell command palette, why not leave it in the global scope for automation?
Now, to make the icon right-clickable:
$QuickTray.Add_MouseDown({ if ($_.Button -eq [System.Windows.Forms.MouseButtons]::Right) { <# run some code here... #> } })Now, if you only want a single powershell script to run replace the script with your own code. If not, we will cover creating the WPF/XAML portion of this app in Part 2.
For now, to test that it works you can replace the comment with this:
[System.Windows.MessageBox]::Show("Hello World!")Now, let's go ahead and see what this looks like by starting the app with these lines:
$QuickTray.Visible = $true [void][System.Windows.Forms.Application]::Run($appContext)To get a copy of the script, check it out on Gist
-
[On-Hold] Running Selenium Quick-Commands
10/08/2022 at 07:10 • 2 commentsI want my first set of quick commands to be selenium-based. I need to select a good module/package/library for using them. I would like to use the NuGet version, but I can't quite remember what was required to get that one going... I'll find that out before my next log for the weekend
Nicholas Jackson