Close
0%
0%

PowerShell Quick Tray

Get a notification-tray-located palette for running powershell commands

Public Chat
Similar projects worth following
133 views
0 followers
Concept for now is to get a tray that has some quick powershell commands in it.

Goals:

[WIP] - Fixed Commands
[ ] - JSON-based Config file for setting quick commands

[ ] - Port to Ubuntu/Chrome OS (my other 2 laptops)

[ ] - Search/Run Bar
[ ] - Command History
  • PowerShell's Read Line

    Nicholas Jackson10/11/2022 at 02:18 0 comments

    So, 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

    Nicholas Jackson10/10/2022 at 04:17 4 comments

    Originally, 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

    Nicholas Jackson10/09/2022 at 21:16 4 comments

    So, 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

    Nicholas Jackson10/09/2022 at 17:54 0 comments

    The 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-TypeAssemblyName System.Windows.Forms,PresentationFramework

    To 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

    Nicholas Jackson10/08/2022 at 07:10 2 comments

    I 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

View all 5 project logs

  • 1
    Powershell Setup: Installing Modules and Packages on Windows

    (Assumed) Initial State:

    • I want to minimize changing of user rights on my machine, so that what I do can be replicated elsewhere. 
    • Assuming no admin rights, and no write access C:\Program Files and C:\Windows, you can run the following to install modules and packages.

    Installing Modules (from PowerShell-Gallery):

    To install powershell modules without admin rights, save the module to a custom file path instead of the default one:

    Find-Module -Name XXX | Save-Module -Path ".\lib\XXX"

    Installing Packages (from Nuget/PackageManagement):

    Make sure to register NuGet as a package provider with:

    Install−PackageProvider −Name Nuget −Force

    Then make sure to register NuGet as a package source with:

    Register-PackageSource -provider NuGet -name NuGetGallery -location https://www.nuget.org/api/v2 -trusted

     **NOTE: at time of this log, this command invokes the V2 API despite the V3 API being available. Currently, while that is true, the V3 API isn't as widely supported yet, so V2 is still currently the "most stable"

    To check your work, run these commands:

    Get-PackageProvider;
    Get-PackageSource;

     If you need to unregister a package source, you can do so with:

    Unregister-PackageSource -Name XXXX

    where XXXX is the name listed from Get-PackageSource.

    As far as I currently know, the provider field/property returned from Get-PackageSource should match one of the names from Get-PackageProvider 

    To install a package:

    Find-Package -name XXXX -ProviderName NuGet | \
    Install-Package -Destination ".\lib"

    Or alternatively, you can use the name of the source to do the install:

    Find-Package -name XXXX -Source NuGetGallery | \
    Install-Package -Destination ".\lib"

View all instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates