AutoPowerShell wiki
SCREENSHOTS!

Screenshots

Button Launcher:

Script Output. This output was generated by "cd c:\windows\system32\drivers\etc;dir"

Script Properties. These are the properties for that script that produced the output above.

Global Options. The second tab (not shown) lets you control global script options, such as which profile scripts to process and suppressing outputs or prompts globally.

Examples

If you're interested in AutoPowerShell, you probably already have a good idea of how powershell scripts work. If not, you may want to head over to msdn.microsoft.com and read the getting started guide, or hit up #powershell on irc.freenode.net. Either way, here are a few scripts that I think make good candidates for AutoPowerShell buttons.

Launchy

Param([Parameter(Mandatory=$true)]$launch_name)
trap [Exception] {
    (new-object -com shell.application).ShellExecute($launch_name)
    break
}
&$launch_name


This script behaves much like the "Run Command" dialog of windows. The first thing that will happen when you run this script in AutoPowerShell is that a popup window will appear prompting your for the value of $launch_name.

Type in any string and the script will then continue to execute. Next it's going to try to execute the argument as if it was a powershell command (& is the "call this" operator). Because one AutoPowerShell script can call any of the others, you could put the name of another script here, or a builtin ps command. If it can't execute the $launch_name as powershell command, the runspace will throw an exception and execution will pass into the trap block. The ShellExecute method of shell.application is the same function that's called by Run Command, so if launchname is a program in the path (like notepad) or a url, or a unc to a server share, then explorer will open it. If $launch_name isn't valid for ShellExecute, then the output window will be displayed with an error message.

This script could be adapted to run snippets of powershell code, or search the start menu for shortcuts to run. You could give it a persistent runspace and have it keep a history of recently launched items. This would be a could candidate for a hotkey.

MonitorFolder

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

$ol = New-Object -comObject Outlook.Application 
$mapi = $ol.Getnamespace("MAPI")
$folder = $mapi.PickFolder()
$old_count = $folder.UnReadItemCount
while ($true)
{
     if ($old_count -lt $folder.UnReadItemCount)
    {
        $not = new-object System.Windows.Forms.NotifyIcon
        $not.Icon = new-object System.Drawing.Icon("computer.ico")
        $not.visible = $true
        $not.BalloonTipText = "New items found in $($folder.FolderPath)" 
        $not.ShowBalloonTip(5)
        sleep 5
        $not.dispose()
    }
    $old_count = $folder.UnReadItemCount
    sleep 2
}

This script requires MS Outlook, and an icon (.ico) file. Although Outlook will do a good job of notifying the user when a new item arrives in his or her Inbox, it is not possible to receive the same notification for any public folders or other users mailbox accounts that are opened. When this script is run, the Outlook folder chooser dialog is shown:

The user just clicks on the folder he or she wants to watch. When an unread item is detected, a message is displayed in the notification area.

The reason this type of script is well suited for AutoPowerShell is that if you tried to run it in the default host, it would tie up the entire console while waiting for mail to arrive. Using AutoPowerShell's Running Scripts feature, the status of a script can be viewed and the script can be stopped.

And right click...

.h2 spell-check

import-module wasp
add-pssnapin pscx

$h = (select-window | ? { $_.isactive -eq $true }).Handle
send-keys "^c" -window $h
$word_app = New-Object -comObject Word.Application 
$newdoc = $word_app.Documents.Add()
$word_app.Visible = $false
$newdoc.activate()
$oldtext = get-clipboard
$word_app.Selection.TypeText( $oldtext )
$newdoc.CheckSpelling()
$word_app.Visible = $false
$word_app.Selection.WholeStory();
$newtext = $word_app.Selection.Text
$newdoc.Close($false)
$word_app.Quit($false)
if ($newtext -ne $oldtext)
{
    set-clipboard -text $newtext.trim()
    send-keys "^v" -window $h
}

This script requires the WASP (*) module and PowerShell Community Extensions. Also requires Microsoft Word to be installed. Set the script property "SuppressOutput" to "true" on this script to hide any error message that may show up from those two modules. Select some text (in any window) that you want to spell check, and click the button for the spell-check script. A background instance of word will perform its spell check on your string. The string is moved into the word program by the clipboard pscx function, word fixes the spelling, and then its pasted back. This works as long as the program you're trying to spell check in supports Ctrl-V for paste.


This script is not only well suited to AutoPowerShell, but it actually won't work at all in the default host. You could select the text in your work window, but after typing the command into the powershell console the text to spell check would be lost in a background window. You would have to pass the text to spell check in as an argument. This script is also a good candidate for a hotkey.

(*) a modified version of WASP is required in order to omit the window argument to send-keys as is done here.

Also available in: HTML TXT