write a PowerShell script App for Splitting Long Text for ChatGPT
Description:
I would like to request the development of a desktop application, written entirely in PowerShell, that can split long text, documents, or prompts into smaller, manageable sections for use with ChatGPT. The application should have the following key features and UI elements:
Main Window:
- The main window should serve as the primary interface for the application.
- It should have a clean and minimalist design, similar to the "Chat GPT splitter" website.
- The window should be resizable and have a fixed aspect ratio to maintain the optimal layout.
- The window should include a header with the application's logo, branding, and main navigation menu.
- The content area should be the central focus, where the text splitting functionality is displayed.
- An optional sidebar could be included to provide additional features or settings.
- A footer area could be added to display additional information or controls.
Content Area:
- The content area should include a large, resizable text input field where users can paste their long text, documents, or prompts.
- Real-time display of the character, word, and paragraph count for the input text.
- A visual indicator or notification to inform users about the maximum character limit per page.
- A prominent "Split" button that triggers the text splitting functionality.
- The output area should display the split text, with the following prepended to each section:
"Do not answer yet. This is just another part of the text I want to send you. Just receive and acknowledge as "Part X/Y" and wait for the next part.
[START PART X/Y]"
- Copy buttons should be provided for each split section.
- A collapsible section to show the user's previous split text, allowing them to restore or copy from the history.
Toolbar and Menus:
- The application should have a toolbar at the top, providing quick access to common actions and settings.
- The toolbar could include buttons for New (clear the input field), Open (load a file), Save (save the split text), and Settings (access application settings).
- The application should also have a traditional menu bar with options for File (New, Open, Save, Exit), Edit (Copy, Paste, Select All), View (Zoom, Toggle Sidebar), Settings, and Help.
Settings and Preferences:
- The application should have a dedicated settings window or panel, where users can customize options such as the character limit per page, auto-save settings, print-friendly output options, and appearance (theme, font, etc.).
File Handling:
- The application should support loading and saving text files, PDFs, or other supported document formats.
- Users should be able to open files, and the application should automatically split the content.
- The split text should be savable in a custom file format or as a plain text file.
Keyboard Shortcuts:
- The application should provide keyboard shortcuts for common actions, such as Ctrl+N for New, Ctrl+O for Open, Ctrl+S for Save, Ctrl+C for Copy, and Ctrl+V for Paste.
Notifications and Feedback:
- The application should provide clear and informative notifications for various actions, such as successful text splitting, reaching the character limit, saving or loading files, and error messages or warnings.
Platform Integration:
- The application should integrate with native PowerShell features, such as file system operations, clipboard management, and system notifications.
Responsive Design and Accessibility:
- The application should be designed with responsive principles, ensuring a consistent and optimal user experience across different screen sizes and resolutions.
- Accessibility features should be implemented, such as support for high-contrast modes and keyboard navigation.
# Import necessary assemblies for the GUI
Add-Type -AssemblyName PresentationFramework
function Create-MainWindow {
[xml]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ChatGPT Text Splitter" Height="500" Width="800" ResizeMode="CanResizeWithGrip">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- Header -->
<TextBlock Grid.Row="0" Text="ChatGPT Text Splitter" FontSize="20" FontWeight="Bold" Margin="10" HorizontalAlignment="Center"/>
<!-- Content Area -->
<DockPanel Grid.Row="1" Margin="10">
<StackPanel DockPanel.Dock="Top" Orientation="Vertical">
<TextBox Name="InputTextBox" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" Height="200" Margin="0,0,0,10"/>
<TextBlock Name="CharCountText" Text="Characters: 0" Margin="0,0,0,5"/>
<TextBlock Name="WordCountText" Text="Words: 0" Margin="0,0,0,5"/>
<TextBlock Name="ParagraphCountText" Text="Paragraphs: 0" Margin="0,0,0,10"/>
<Button Name="SplitButton" Content="Split" Width="100" Margin="0,0,0,10" HorizontalAlignment="Left"/>
</StackPanel>
<ScrollViewer DockPanel.Dock="Bottom" Height="200" VerticalScrollBarVisibility="Auto">
<StackPanel Name="OutputStackPanel" Orientation="Vertical"/>
</ScrollViewer>
</DockPanel>
<!-- Footer -->
<TextBlock Grid.Row="2" Text="© 2024 Your Company" HorizontalAlignment="Center" Margin="10"/>
</Grid>
</Window>
"@
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$window = [Windows.Markup.XamlReader]::Load($reader)
# Find elements
$inputTextBox = $window.FindName("InputTextBox")
$charCountText = $window.FindName("CharCountText")
$wordCountText = $window.FindName("WordCountText")
$paragraphCountText = $window.FindName("ParagraphCountText")
$splitButton = $window.FindName("SplitButton")
$outputStackPanel = $window.FindName("OutputStackPanel")
# Event Handlers
$inputTextBox.Add_TextChanged({
$charCountText.Text = "Characters: " + $inputTextBox.Text.Length
$wordCountText.Text = "Words: " + ($inputTextBox.Text -split '\s+').Count
$paragraphCountText.Text = "Paragraphs: " + ($inputTextBox.Text -split '\r\n|\r|\n').Count
})
$splitButton.Add_Click({
$outputStackPanel.Children.Clear()
$text = $inputTextBox.Text
$maxCharCount = 2048
$parts = [math]::Ceiling($text.Length / $maxCharCount)
for ($i = 0; $i -lt $parts; $i++) {
$start = $i * $maxCharCount
$length = [math]::Min($maxCharCount, $text.Length - $start)
$partText = $text.Substring($start, $length)
$partLabel = "Part " + ($i + 1) + "/" + $parts
$outputText = "Do not answer yet. This is just another part of the text I want to send you. Just receive and acknowledge as `$partLabel` and wait for the next part.`n[START $partLabel]`n$partText"
$textBox = New-Object System.Windows.Controls.TextBox
$textBox.Text = $outputText
$textBox.Margin = "0,0,0,10"
$textBox.AcceptsReturn = $true
$textBox.VerticalScrollBarVisibility = "Auto"
$textBox.IsReadOnly = $true
$button = New-Object System.Windows.Controls.Button
$button.Content = "Copy"
$button.Tag = $outputText
$button.Margin = "0,0,0,10"
$button.Add_Click({
$currentButton = $_.Source
[System.Windows.Clipboard]::SetText($currentButton.Tag)
[System.Windows.MessageBox]::Show("Text copied to clipboard")
})
$stackPanel = New-Object System.Windows.Controls.StackPanel
$stackPanel.Orientation = "Vertical"
$stackPanel.Children.Add($textBox)
$stackPanel.Children.Add($button)
$outputStackPanel.Children.Add($stackPanel)
}
})
# Show the window
$window.ShowDialog() | Out-Null
}
Create-MainWindow
# Import necessary assemblies for the GUI
Add-Type -AssemblyName PresentationFramework
function Create-MainWindow {
[xml]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ChatGPT Text Splitter" Height="500" Width="800" ResizeMode="CanResizeWithGrip">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- Header -->
<TextBlock Grid.Row="0" Text="ChatGPT Text Splitter" FontSize="20" FontWeight="Bold" Margin="10" HorizontalAlignment="Center"/>
<!-- Content Area -->
<DockPanel Grid.Row="1" Margin="10">
<StackPanel DockPanel.Dock="Top" Orientation="Vertical">
<TextBox Name="InputTextBox" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" Height="200" Margin="0,0,0,10"/>
<TextBlock Name="CharCountText" Text="Characters: 0" Margin="0,0,0,5"/>
<TextBlock Name="WordCountText" Text="Words: 0" Margin="0,0,0,5"/>
<TextBlock Name="ParagraphCountText" Text="Paragraphs: 0" Margin="0,0,0,10"/>
<Button Name="SplitButton" Content="Split" Width="100" Margin="0,0,0,10" HorizontalAlignment="Left"/>
<StackPanel Orientation="Horizontal" Margin="0,0,0,10">
<TextBlock Text="Max Characters Per Part:" VerticalAlignment="Center" Margin="0,0,10,0"/>
<TextBox Name="MaxCharCountTextBox" Width="100" Text="2048"/>
</StackPanel>
</StackPanel>
<ScrollViewer DockPanel.Dock="Bottom" Height="200" VerticalScrollBarVisibility="Auto">
<StackPanel Name="OutputStackPanel" Orientation="Vertical"/>
</ScrollViewer>
</DockPanel>
<!-- Footer -->
<TextBlock Grid.Row="2" Text="© 2024 Your Company" HorizontalAlignment="Center" Margin="10"/>
</Grid>
</Window>
"@
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$window = [Windows.Markup.XamlReader]::Load($reader)
# Find elements
$inputTextBox = $window.FindName("InputTextBox")
$charCountText = $window.FindName("CharCountText")
$wordCountText = $window.FindName("WordCountText")
$paragraphCountText = $window.FindName("ParagraphCountText")
$splitButton = $window.FindName("SplitButton")
$outputStackPanel = $window.FindName("OutputStackPanel")
$maxCharCountTextBox = $window.FindName("MaxCharCountTextBox")
# Event Handlers
$inputTextBox.Add_TextChanged({
$charCountText.Text = "Characters: " + $inputTextBox.Text.Length
$wordCountText.Text = "Words: " + ($inputTextBox.Text -split '\s+').Count
$paragraphCountText.Text = "Paragraphs: " + ($inputTextBox.Text -split '\r\n|\r|\n').Count
})
$splitButton.Add_Click({
$outputStackPanel.Children.Clear()
$text = $inputTextBox.Text
[int]$maxCharCount = [int]$maxCharCountTextBox.Text
$parts = [math]::Ceiling($text.Length / $maxCharCount)
for ($i = 0; $i -lt $parts; $i++) {
$start = $i * $maxCharCount
$length = [math]::Min($maxCharCount, $text.Length - $start)
$partText = $text.Substring($start, $length)
$partLabel = "Part " + ($i + 1) + "/" + $parts
$outputText = "Do not answer yet. This is just another part of the text I want to send you. Just receive and acknowledge as `$partLabel` and wait for the next part.`n[START $partLabel]`n$partText"
$textBox = New-Object System.Windows.Controls.TextBox
$textBox.Text = $outputText
$textBox.Margin = "0,0,0,10"
$textBox.AcceptsReturn = $true
$textBox.VerticalScrollBarVisibility = "Auto"
$textBox.IsReadOnly = $true
$button = New-Object System.Windows.Controls.Button
$button.Content = "Copy"
$button.Tag = $outputText
$button.Margin = "0,0,0,10"
$button.Add_Click({
$currentButton = $_.Source
[System.Windows.Clipboard]::SetText($currentButton.Tag)
[System.Windows.MessageBox]::Show("Text copied to clipboard")
})
$stackPanel = New-Object System.Windows.Controls.StackPanel
$stackPanel.Orientation = "Vertical"
$stackPanel.Children.Add($textBox)
$stackPanel.Children.Add($button)
$outputStackPanel.Children.Add($stackPanel)
}
})
# Show the window
$window.ShowDialog() | Out-Null
}
Create-MainWindow
# Import necessary assemblies for the GUI
Add-Type -AssemblyName PresentationFramework
function Create-MainWindow {
[xml]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ChatGPT Text Splitter" Height="500" Width="800" ResizeMode="CanResizeWithGrip">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- Header -->
<TextBlock Grid.Row="0" Text="ChatGPT Text Splitter" FontSize="20" FontWeight="Bold" Margin="10" HorizontalAlignment="Center"/>
<!-- Content Area -->
<DockPanel Grid.Row="1" Margin="10">
<StackPanel DockPanel.Dock="Top" Orientation="Vertical">
<TextBox Name="InputTextBox" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" Height="200" Margin="0,0,0,10"/>
<TextBlock Name="CharCountText" Text="Characters: 0" Margin="0,0,0,5"/>
<TextBlock Name="WordCountText" Text="Words: 0" Margin="0,0,0,5"/>
<TextBlock Name="ParagraphCountText" Text="Paragraphs: 0" Margin="0,0,0,10"/>
<StackPanel Orientation="Horizontal" Margin="0">
<TextBlock Text="Max Characters Per Part:" VerticalAlignment="Center" Margin="0,0,5,0"/>
<TextBox Name="MaxCharCountTextBox" Width="100" Text="2048" Margin="0,0,5,0"/>
<Button Name="SplitButton" Content="Split" Width="100" Margin="0,0,5,0" HorizontalAlignment="Right"/>
</StackPanel>
</StackPanel>
<ScrollViewer DockPanel.Dock="Bottom" Height="200" VerticalScrollBarVisibility="Auto">
<StackPanel Name="OutputStackPanel" Orientation="Vertical"/>
</ScrollViewer>
<ProgressBar Name="ProgressBar" Visibility="Collapsed" Height="20" Margin="10" />
</DockPanel>
<!-- Footer -->
<TextBlock Grid.Row="2" Text="© 2024 Your Company" HorizontalAlignment="Center" Margin="10"/>
</Grid>
</Window>
"@
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$window = [Windows.Markup.XamlReader]::Load($reader)
# Find elements
$inputTextBox = $window.FindName("InputTextBox")
$charCountText = $window.FindName("CharCountText")
$wordCountText = $window.FindName("WordCountText")
$paragraphCountText = $window.FindName("ParagraphCountText")
$splitButton = $window.FindName("SplitButton")
$outputStackPanel = $window.FindName("OutputStackPanel")
$maxCharCountTextBox = $window.FindName("MaxCharCountTextBox")
$progressBar = $window.FindName("ProgressBar")
# Event Handlers
$inputTextBox.Add_TextChanged({
$charCountText.Text = "Characters: " + $inputTextBox.Text.Length
$wordCountText.Text = "Words: " + ($inputTextBox.Text -split '\s+').Count
$paragraphCountText.Text = "Paragraphs: " + ($inputTextBox.Text -split '\r\n|\r|\n').Count
})
$splitButton.Add_Click({
$progressBar.Visibility = "Visible"
$outputStackPanel.Children.Clear()
$text = $inputTextBox.Text
[int]$maxCharCount = [int]$maxCharCountTextBox.Text
$parts = [math]::Ceiling($text.Length / $maxCharCount)
$quickCopyButtonStackPanel = New-Object System.Windows.Controls.WrapPanel
$quickCopyButtonStackPanel.Orientation = "Horizontal"
for ($i = 0; $i -lt $parts; $i++) {
$start = $i * $maxCharCount
$length = [math]::Min($maxCharCount, $text.Length - $start)
$partText = $text.Substring($start, $length)
$partLabel = "Part " + ($i + 1) + " of " + $parts
$outputText = "Do not answer yet. This is just another part of the text I want to send you. Just receive and acknowledge as `$partLabel` and wait for the next part.`n[START $partLabel]`n$partText"
$textBox = New-Object System.Windows.Controls.TextBox
$textBox.Text = $outputText
$textBox.Margin = "0,0,0,10"
$textBox.AcceptsReturn = $true
$textBox.VerticalScrollBarVisibility = "Auto"
$textBox.IsReadOnly = $true
$textBox.MaxLines = 8
$textBox.VerticalScrollBarVisibility = "Auto"
$textBox.HorizontalScrollBarVisibility = "Auto"
$textBox.ResizeMode = "CanResizeWithGrip"
$copyButton = New-Object System.Windows.Controls.Button
$copyButton.Content = "Copy"
$copyButton.Tag = $outputText
$copyButton.Add_Click({
$currentButton = $_.Source
[System.Windows.Clipboard]::SetText($currentButton.Tag)
})
$quickCopyButton = New-Object System.Windows.Controls.Button
$quickCopyButton.Content = "Copy " + ($i + 1) + "/" + $parts
$quickCopyButton.Tag = $outputText
$quickCopyButton.Add_Click({
if ($quickCopyButton.Background -eq "LightBlue") {
$quickCopyButton.Background = "Transparent"
} else {
$quickCopyButton.Background = "LightBlue"
}
$currentButton = $_.Source
[System.Windows.Clipboard]::SetText($currentButton.Tag)
})
$quickCopyButtonStackPanel.Children.Add($quickCopyButton)
$stackPanel = New-Object System.Windows.Controls.StackPanel
$stackPanel.Orientation = "Vertical"
$stackPanel.Children.Add($textBox)
$stackPanel.Children.Add($copyButton)
$separator = New-Object System.Windows.Controls.Separator
$separator.Margin = "0,5,0,5"
$outputStackPanel.Children.Add($quickCopyButtonStackPanel)
$outputStackPanel.Children.Add($stackPanel)
$outputStackPanel.Children.Add($separator)
}
$progressBar.Visibility = "Collapsed"
})
# Show the window
$window.ShowDialog() | Out-Null
}
Create-MainWindow