# perltxt.a4.ps1 Param( $perl_script_name = $NULL, $document_target_directory = [String]::join('', ($HOME, '\Desktop\PerlTxt Documents')) ) if($perl_script_name -ne $NULL){ $file_name_array = [System.IO.Path]::GetFileName($perl_script_name).split('.') $file_location = [System.IO.Path]::GetDirectoryName($perl_script_name) if( (test-path $perl_script_name -PathType leaf) -and ($file_name_array[-1] -eq 'pl') ){ if ($file_name_array.length -gt 2){ $file_name = [String]::join('.', $file_name_array[0..($file_name_array.length - 2)]) } else { $file_name = $file_name_array[0] } $time = Get-Date -Format 'yyyy-MM-dd-hh-mm-ss' #$time = 'time' $new_file_location = [String]::join('', ([IO.Path]::GetFullPath($document_target_directory), '\', $file_name)) $new_script_name = [String]::join('', ($new_file_location, '\', $file_name, '.', $time, '.pl')) $new_document_name = [String]::join('', ($new_file_location, '\', $file_name, '.', $time, '.txt')) $out = & perl $perl_script_name 2>&1 } } else{ $out = [String]::join([Environment]::NewLine, ( 'No valid .pl (Perl) script specified', '', 'Perl to Text ( perltxt.exe )', '', 'is a hackish and slow tool to run Perl ( .pl ) scripts that are passed to it as an argument,', ' save the scripts and the output to timestamped text files in a directory specified as the second argument', ' ( $HOME\Desktop\PerlTxt Documents\[Script name] is the default ),', ' and load the output onto the Windows clipboard.', '', ' A sound is played when the script has finished and the clipboard is ready.', '', 'Use:> perltxt [path to your_perl.pl script] [optional path to the target directory for the output files]', '', 'Direct comments and suggestions to horstman.jesse@yahoo.com')) } if($out -is [System.Management.Automation.ErrorRecord]) { # email or some other action here #Send-MailMessage -to me@example.com -subject "Error in gpg " -body "Error:`n$out" -from error@example.com -smtpserver smtp.example.com } # Load System.Windows.Forms assembly. $null = [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") # Create a data object. $dataObject = New-Object windows.forms.dataobject # Add generated strings to the data object. $text = $out $dataObject.SetData([Windows.Forms.DataFormats]::UnicodeText, $true, $text) # Place the data object in the system clipboard. [Windows.Forms.Clipboard]::SetDataObject($dataObject, $true) $document = $dataObject.GetData([Windows.Forms.DataFormats]::UnicodeText) if($perl_script_name -ne $NULL){ # if((test-path $document_target_directory -isvalid) -and !(test-path $document_target_directory -pathtype container)){ # new-item $document_target_directory -type directory # } if((test-path $new_file_location -isvalid) -and !(test-path $new_File_location -pathtype container)){ new-item $new_file_location -type directory | Out-Null } #echo "PerlTxt has generated new files in $new_file_location" If(-not(Test-Path -path $new_script_name)) { Copy-Item $perl_script_name $new_script_name } else{ Remove-Item $new_script_name Copy-Item $perl_script_name $new_script_name } If(-not(Test-Path -path $new_document_name)) { New-Item -Path $new_document_name -ItemType file -Value $($document) -force | Out-Null } else{ $stream = [System.IO.StreamWriter] $new_document_name $stream.Write($document) $stream.close() } } cls echo $document [System.Media.SystemSounds]::Asterisk.Play(); exit #### REM perltxt.a4.cmd REM horstman.jesse@yahoo.com @echo off powershell.exe -sta .\perltxt.a4.ps1 %*