ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Clipboard Help+Spell

Writing custom script...?

<< < (2/2)

PaulM:
For what it's worth, this is the basic Powershell script I was messing with... this works on on one computer with Powershell 5.0.  I have another computer with Powershell 5.0 and it doesn't work... so, I've given up figuring out what's going on!  I did try the iterative Foreach, as well... seems to have the same behavior, so... I don't know.  But, anyway, when I try to run it from Clipboard Help+Spell, it just brings up a Windows Explorer window of the Clipboard Help+Spell directory...?!?  You don't what to see the copy with all the comments indicating all the changes... it's a total mess!

# powershell -ExecutionPolicy Bypass -File Drive:\Path\to\file\ClipboardEntryParse.ps1

function Get-Clipboard([switch] $Lines) {
   if($Lines) {
      $cmd = {
         Add-Type -Assembly PresentationCore
         [Windows.Clipboard]::GetText() -replace "`r", '' -split "`n"
      }
   } else {
      $cmd = {
         Add-Type -Assembly PresentationCore
         [Windows.Clipboard]::GetText()
      }
   }
   if([threading.thread]::CurrentThread.GetApartmentState() -eq 'MTA') {
      & powershell -Sta -Command $cmd
   } else {
      & $cmd
   }
}

function Out-Clipboard {
    [cmdletbinding()]
    param (
        [parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)]$InputObject,
        [switch] $File
    )
    begin {
        $ps = [PowerShell]::Create()
        $rs = [RunSpaceFactory]::CreateRunspace()
        $rs.ApartmentState = "STA"
        $rs.ThreadOptions = "ReuseThread"
        $rs.Open()
        $data = @()
    }
    process {$data += $InputObject}
    end {
        $rs.SessionStateProxy.SetVariable("do_file_copy", $File)
        $rs.SessionStateProxy.SetVariable("data", $data)
        $ps.Runspace = $rs
        $ps.AddScript({
            Add-Type -AssemblyName 'System.Windows.Forms'
            if ($do_file_copy) {
                $file_list = New-Object -TypeName System.Collections.Specialized.StringCollection
                $data | % {
                    if ($_ -is [System.IO.FileInfo]) {[void]$file_list.Add($_.FullName)}
                    elseif ([IO.File]::Exists($_))    {[void]$file_list.Add($_)}
                }
                [System.Windows.Forms.Clipboard]::SetFileDropList($file_list)
            } else {
                $host_out = (($data | Out-String -Width 1000) -split "`n" | % {$_.TrimEnd()}) -join "`n"
                [System.Windows.Forms.Clipboard]::SetText($host_out)
            }
        }).Invoke()
    }
}



$text = [String]::Join(' ', (Get-Clipboard))
  [regex]::Matches($text, '(\w+(?:[-'']\w+)*)') |
  ForEach-Object { Out-Clipboard $_.Value  }

PaulM:
Hi:

Perhaps there's one thing that someone here can help me understand better...  When something gets copied to the clipboard what are the conditions that determine whether or not Clipboard Help+Spell will save the current entry,... that is, push the current clipboard entry onto it's stack or queue?  As opposed, perhaps, to the current entry just being overwritten, and not being pushed onto Clipboard Help+Spell stack or queue?

Is this determined entirely by Clipboard Help+Spell, or does it depend entirely on the particular method used to place contents on the clipboard, or is it some combination of the two?

Thanks

Navigation

[0] Message Index

[*] Previous page

Go to full version