Posts

Showing posts from 2023

Replacing default paste behavior in Windows 11

Clipboard URL Shortener Implementation Guide

Clipboard URL Shortener Implementation Guide

Powershell Script

This PowerShell script checks the clipboard for a YouTube URL. If it finds one, it converts it to a shortened youtu.be URL and updates the clipboard with this new URL.

Add-Type -AssemblyName System.Windows.Forms

$clipboardText = Get-Clipboard

if ($clipboardText -match 'https://(www\.|music\.)?youtube\.com/watch\?v=([a-zA-Z0-9_-]+)') {
    $videoID = $matches[2]
    $shortUrl = "https://youtu.be/$videoID"
    Set-Clipboard -Value $shortUrl  # Update the clipboard with the shortened URL
} else {
    Set-Clipboard -Value $clipboardText  # Retain the original clipboard text if it's not a YouTube URL
}
        

AutoHotkey Script

This AutoHotkey script intercepts the Ctrl+V keystroke to execute the PowerShell script and then perform a paste operation using Shift+Insert.

^v::
{
    RunWait("C:\Users\joe\bin\yurl.ps1", "", "Hide") ;
    Send("+{Insert}")  ; Perform paste operation using Shift+Insert
}
return
        

How It Works

When you press Ctrl+V, the AutoHotkey script runs the PowerShell script. If the clipboard contains a YouTube URL, the PowerShell script converts it to a shortened youtu.be URL and updates the clipboard. The AutoHotkey script then simulates a Shift+Insert keystroke to paste the (potentially modified) clipboard content, replacing the default Windows paste behavior with shortened URLs. To avoid breaking pasting images, simply use shift+insert if you know the content is graphical. Still working around this.

Well... chatGPT, collab, automation, monolithic code and bad APIs

Let's just be honest about the state of things from an automation standpoint:

import pandas as pd
import re

# Variable Definitions
template_file_name = 'phonebuttontemplate.csv'
device_file_name = 'deviceprofile.csv'
modified_device_file_name = 'deviceprofile_modified.csv'
replacement_value = 'DELETED'
end_column_number = 89
print_line_counts = False  # Flag this if you encounter issues and want to print the Line count for each row in the template csv
first_column_name = 'Device Profile Name'

# Read phonebuttontemplate.csv
print("Reading phonebuttontemplate.csv...")
template_df = pd.read_csv(template_file_name)

# Store header row
header_row_template = list(template_df.columns)

# Initialize a dictionary to store the values
template_dict = {}

# Loop through the DataFrame rows
for _, row in template_df.iterrows():
    name = row.get('NAME', None)
    # Check if the row has a NAME and is not empty
    if pd.notna(name):
        # Check each column for "Line", "Speed Dial", or "None" under the "TYPE OF FEATURE \d{1,2}" pattern
        count = 0
        empty_value_encountered = False
        for col in header_row_template:
            if re.match(r'TYPE OF FEATURE \d{1,2}', col):
                value = row[col]
                if value == 'Line':
                    count += 1
                elif value == 'None':
                    empty_value_encountered = True
                    break
        # If an empty value was encountered, stop counting and break the loop
        if empty_value_encountered:
            break
        template_dict[name] = {'count': count + 1}  # Start the count from 1
        # If print_line_counts is True, print the name of the template and the count of its lines
        if print_line_counts:
            print(f"{name}: {count + 1} lines")

# Read deviceprofile.csv
print("Reading deviceprofile.csv...")
device_df = pd.read_csv(device_file_name)

# Store header row
header_row_device = list(device_df.columns)

# Iterate over the rows in deviceprofile.csv
for index, row in device_df.iterrows():
    template_name = row['Phone Button Template']
    device_profile_name = row[first_column_name]

    if pd.notna(template_name) and pd.notna(device_profile_name):
        # Check if the template name exists in the template_dict
        if template_name in template_dict:
            template_info = template_dict[template_name]
            count = template_info['count']
            directory_number_col = f'Directory Number {count}'
            call_id_presentation_col = f'Calling Line ID Presentation When Diverted {end_column_number}'
            device_df.loc[index, directory_number_col:call_id_presentation_col] = replacement_value

# Write the DataFrame to a new file
device_df.to_csv(modified_device_file_name, index=False)

print("Processing completed successfully.")

The prominent issue in terms of coding is chatGPT, which needs to be addressed when considering collaboration (collab).

To begin with, it would be beneficial to develop a universal UC API that can merge various methods and functions, enabling the automation of any task. Although this idea is intriguing, it necessitates the complete rewriting of these large-scale applications. The goal would be to leverage AI and prioritize an API-first approach.

Once this is accomplished, a standardized UC dashboard could be implemented. This would unify platforms like Webex and CUCM, allowing for seamless provisioning, integration, and communication without the need for intermediary components. These components were not specifically designed for the purpose and still rely on outdated Unix code, essentially being rooted in the Tandberg system.

I propose a significant transformation, a genuine movement empowered by AI, to bring UC up to date and in line with current advancements.

Anyhow, that's my hot-take.  I am working on automating all the provisioning in my lab, check back here in a couple months.  Maybe I will have a solid solution.  As it stands right now I just have a certificate generation, request and load API for various UC devices.  

That is the start of my ucEngineersToolKit API

Good day and may it be a great one!

Lab Rebuild

So, we have been rebuilding the lab, ESXi is back up and I am getting my VM's ready.
I will post an update once I am ready :)