Powershell GUI fronted (WPF) to run categorized console scripts

⌈⌋ branch:  ClickyColoury


Artifact [9e64dc689c]

Artifact 9e64dc689c51625576ebdf0a3e8eb8e4958117ae:

  • File tools/plugins/menu_usertools.ps1 — part of check-in [dafc0b50d4] at 2017-09-24 06:58:35 on branch trunk — Made Usertools base dir configurable (user: mario size: 1814)

# api: multitool
# type: init-gui
# version: 0.6
# title: UserTools
# description: register .\UserTools\
# hidden: 1
# category: edit
# config: { name: cfg.usertools, value: .\UserTools, type: str, description: shortcut source directory }
#
# Each entry copies the respective file to the user desktop
# (Requires `hostname` and `username` to be set.)

if ((!$CLI) -and (!$e) -and ($GUI.w) -and ($m = $GUI.w.findName("Menu_USERTOOLS"))) {
    $m = $m.Items
    
    if (!($cfg.usertools)) {
       $cfg.usertools = ".\UserTools"
    }

    #-- extract description file
    $desc = Import-CSV ".\data\usertools.description.csv"

    #-- add menu entries
    ForEach ($file in (dir "$($cfg.usertools)\*.*")) {
        $fn = $file.Name

        #-- MenuItem + Image
        $meta = $desc | ? { $_.file -eq $fn }
        if (!$meta) { $meta = @{icon="icon.copy.png"; desc=""} }
        $ICON = W Image @{Source=(Get-IconPath $meta.icon); Height=18; Width=18}
        $m.Add((W MenuItem @{Header="_$fn"; Tooltip=$meta.desc; Icon=$ICON; Add_click={ copy-UserTool "$fn" }.getnewclosure()}))
    }

    #-- handler
    function Copy-UserTool($fn) {
        Out-Gui -b Blue -f Cyan "User Tools install                          "
        $machine = $GUI.machine.Text
        $username = $GUI.username.Text

        #-- verify host+user
        if (!$machine) {
            Out-Gui -f Red "No hostname given"
        }
        else {
            if ((!$username) -or (!(Test-Path "\\$machine\c$\Users\$username\Desktop\"))) {
                $username = "Public"
            }
            $dest = "\\$machine\c$\Users\$username\Desktop\"

            #-- copy
            Out-Gui "❏ '$fn' to $dest"
            Copy "$($cfg.usertools)\$fn" "$dest"
        }
    }
}