Comments (7)
You will need the latest build, fixed an issue with ReplaceRegex, https://github.com/sabrogden/Ditto/releases/tag/nightly
Cisco
// Remove any non-alphanumeric characters (like colons, hyphens, etc.)
clip.AsciiTextReplaceRegex("[^a-zA-Z0-9]", "");
// Insert a hyphen every 2 characters
clip.AsciiTextReplaceRegex("(.{4})", "$1.");
var text = clip.GetAsciiString();
if(text.size == 15)
{
//remove the - at the end of the string
var text = clip.GetAsciiString();
var clean = text.substr(0, 14);
// Set the modified MAC address back to the clipboard
clip.SetAsciiString(clean);
}
else
{
// If the MAC address is not of the expected length, log an error or handle it appropriately
clip.SetAsciiString("Error: MAC address format incorrect");
}
return false;
Microsoft
// Remove any non-alphanumeric characters (like colons, hyphens, etc.)
clip.AsciiTextReplaceRegex("[^a-zA-Z0-9]", "");
// Insert a hyphen every 2 characters
clip.AsciiTextReplaceRegex("(.{2})", "$1-");
var text = clip.GetAsciiString();
if(text.size == 18)
{
//remove the - at the end of the string
var text = clip.GetAsciiString();
var clean = text.substr(0, 17);
// Set the modified MAC address back to the clipboard
clip.SetAsciiString(clean);
}
else
{
// If the MAC address is not of the expected length, log an error or handle it appropriately
clip.SetAsciiString("Error: MAC address format incorrect");
}
return false;
Linux
// Remove any non-alphanumeric characters (like colons, hyphens, etc.)
clip.AsciiTextReplaceRegex("[^a-zA-Z0-9]", "");
// Insert a hyphen every 2 characters
clip.AsciiTextReplaceRegex("(.{2})", "$1:");
var text = clip.GetAsciiString();
if(text.size == 18)
{
//remove the - at the end of the string
var text = clip.GetAsciiString();
var clean = text.substr(0, 17);
// Set the modified MAC address back to the clipboard
clip.SetAsciiString(clean);
}
else
{
// If the MAC address is not of the expected length, log an error or handle it appropriately
clip.SetAsciiString("Error: MAC address format incorrect");
}
return false;
from ditto.
Cool
Just gave this a try
to cisco works, however to linux & ms does not
here is test data
from cisco 90E2.BA10.1ABE
to cisco 90E2.BA10.1ABE
to linux 90E2.BA10.1ABE
to ms 90E2.BA10.1ABE
from ms 90-E2-BA-10-1A-BE
to cisco 90E2.BA10.1ABE
to linux 90-E2-BA-10-1A-BE
to ms 90-E2-BA-10-1A-BE
from linux 90:E2:BA:10:1A:BE
to cisco 90E2.BA10.1ABE
to linux 90:E2:BA:10:1A:BE
to ms 90:E2:BA:10:1A:BE
Perhaps I pasted it wrong ?
Running the nightly you suggested
from ditto.
Microsoft and Linux scripts are not updated. I updated my post to format things better. Paste the mac text in the sample and click run to verify each in the script editor.
from ditto.
Hello,
I have just tried the current on paste scripts
They work in all cases
from cisco 90E2.BA10.1ABE
to cisco 90E2.BA10.1ABE
to linux 90:E2:BA:10:1A:BE
to ms 90-E2-BA-10-1A-BE
from ms 90-E2-BA-10-1A-BE
to cisco 90E2.BA10.1ABE
to linux 90:E2:BA:10:1A:BE
to ms 90-E2-BA-10-1A-BE
from linux 90:E2:BA:10:1A:BE
to cisco 90E2.BA10.1ABE
to linux 90:E2:BA:10:1A:BE
to ms 90-E2-BA-10-1A-BE
Chatgpt noticed that
var text = clip.GetAsciiString();
gets called twice and that might be unnecessary
I tested and its right
Here is updated version, confirmed to also work for single line pastes
Cisco
// Remove any non-alphanumeric characters (like colons, hyphens, etc.)
clip.AsciiTextReplaceRegex("[^a-zA-Z0-9]", "");
// Insert a hyphen every 2 characters
clip.AsciiTextReplaceRegex("(.{4})", "$1.");
var text = clip.GetAsciiString();
if(text.size == 15)
{
//remove the - at the end of the string
var clean = text.substr(0, 14);
// Set the modified MAC address back to the clipboard
clip.SetAsciiString(clean);
}
else
{
// If the MAC address is not of the expected length, log an error or handle it appropriately
clip.SetAsciiString("Error: MAC address format incorrect");
}
return false;
Microsoft
// Remove any non-alphanumeric characters (like colons, hyphens, etc.)
clip.AsciiTextReplaceRegex("[^a-zA-Z0-9]", "");
// Insert a hyphen every 2 characters
clip.AsciiTextReplaceRegex("(.{2})", "$1-");
var text = clip.GetAsciiString();
if(text.size == 18)
{
//remove the - at the end of the string
var clean = text.substr(0, 17);
// Set the modified MAC address back to the clipboard
clip.SetAsciiString(clean);
}
else
{
// If the MAC address is not of the expected length, log an error or handle it appropriately
clip.SetAsciiString("Error: MAC address format incorrect");
}
return false;
Linux
// Remove any non-alphanumeric characters (like colons, hyphens, etc.)
clip.AsciiTextReplaceRegex("[^a-zA-Z0-9]", "");
// Insert a hyphen every 2 characters
clip.AsciiTextReplaceRegex("(.{2})", "$1:");
var text = clip.GetAsciiString();
if(text.size == 18)
{
//remove the - at the end of the string
var clean = text.substr(0, 17);
// Set the modified MAC address back to the clipboard
clip.SetAsciiString(clean);
}
else
{
// If the MAC address is not of the expected length, log an error or handle it appropriately
clip.SetAsciiString("Error: MAC address format incorrect");
}
return false;
from ditto.
Now I have three questions
How can I give these script in a way that they can add them easily, like, a two click operation to add all 3 ?
And, how to make these scripts multi-line
and, how to put these 3 scripts into a sub-context menu in the special paste menu as it is already getting long and presumably there are many other good paste scripts to create !
Example
Also also, there should be a way to re-order On Paste Script, without having to delete and re-type them
Here is what I mean
https://github.com/sabrogden/Ditto/assets/10621885/25a32703-125e-4252-8993-31f671fb34c7
(Also I note, you can't use Ditto, while inside Ditto settings ! It is only because the window is unclickable due to having child windows, I think that is just a window hWnd flag ?)
from ditto.
Ok, I got it, multiline and single line capable version all in one
Convert MAC to Cisco format
// Function to manually remove non-alphanumeric characters and format a MAC address
def processLine(line) {
// Manually remove non-alphanumeric characters
var cleanedLine = "";
for (c : line) {
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
cleanedLine += c;
}
}
// Manually insert periods to format as Cisco MAC address
if (cleanedLine.size() == 12) {
return cleanedLine.substr(0, 4) + "." + cleanedLine.substr(4, 4) + "." + cleanedLine.substr(8, 4);
}
return "Error: MAC address format incorrect"; // Error handling
}
// Get the entire clipboard content
var allText = clip.GetAsciiString();
var processedText = "";
var start = 0;
// Manually iterate over each line in allText
for (var i = 0; i <= allText.size(); ++i) {
if (i == allText.size() || allText[i] == '\n') {
// Extract the current line
var line = allText.substr(start, i - start);
// Process the current line and append to processedText
processedText += processLine(line);
// Add a newline if it's not the last line
if (i != allText.size()) {
processedText += "\n";
}
// Update the start index for the next line
start = i + 1;
}
}
// Set the modified text back to the clipboard
clip.SetAsciiString(processedText);
return false; // Continue with the paste operation
Convert MAC to Microsoft format
// Function to manually format a MAC address in the Microsoft format
def processLineToMicrosoftFormat(line) {
// Manually remove non-alphanumeric characters
var cleanedLine = "";
for (c : line) {
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
cleanedLine += c;
}
}
// Manually insert hyphens every 2 characters, except for the end
var formattedLine = "";
for (var i = 0; i < cleanedLine.size(); ++i) {
formattedLine += cleanedLine[i];
if (i % 2 == 1 && i < cleanedLine.size() - 1) { // Check to avoid adding hyphen at the end
formattedLine += "-";
}
}
// Check if the formatted line is of the correct length for a Microsoft format MAC address
if (formattedLine.size() == 17) { // 12 characters + 5 hyphens = 17 characters
return formattedLine;
}
return "Error: MAC address format incorrect"; // Error handling
}
// Get the entire clipboard content
var allText = clip.GetAsciiString();
var processedText = "";
var start = 0;
// Manually iterate over each line in allText
for (var i = 0; i <= allText.size(); ++i) {
if (i == allText.size() || allText[i] == '\n') {
// Extract the current line
var line = allText.substr(start, i - start);
// Process the current line and append to processedText
processedText += processLineToMicrosoftFormat(line);
// Add a newline if it's not the last line
if (i != allText.size()) {
processedText += "\n";
}
// Update the start index for the next line
start = i + 1;
}
}
// Set the modified text back to the clipboard
clip.SetAsciiString(processedText);
return false; // Continue with the paste operation
Convert MAC to Linux format
// Function to manually format a MAC address in the Linux format
def processLineToLinuxFormat(line) {
// Manually remove non-alphanumeric characters
var cleanedLine = "";
for (c : line) {
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
cleanedLine += c;
}
}
// Manually insert colons every 2 characters, except for the end
var formattedLine = "";
for (var i = 0; i < cleanedLine.size(); ++i) {
formattedLine += cleanedLine[i];
if (i % 2 == 1 && i < cleanedLine.size() - 1) { // Check to avoid adding colon at the end
formattedLine += ":";
}
}
// Check if the formatted line is of the correct length for a Linux format MAC address
if (formattedLine.size() == 17) { // 12 characters + 5 colons = 17 characters
return formattedLine;
}
return "Error: MAC address format incorrect"; // Error handling
}
// Get the entire clipboard content
var allText = clip.GetAsciiString();
var processedText = "";
var start = 0;
// Manually iterate over each line in allText
for (var i = 0; i <= allText.size(); ++i) {
if (i == allText.size() || allText[i] == '\n') {
// Extract the current line
var line = allText.substr(start, i - start);
// Process the current line and append to processedText
processedText += processLineToLinuxFormat(line);
// Add a newline if it's not the last line
if (i != allText.size()) {
processedText += "\n";
}
// Update the start index for the next line
start = i + 1;
}
}
// Set the modified text back to the clipboard
clip.SetAsciiString(processedText);
return false; // Continue with the paste operation
Proof testing, multi line and single line
From cisco
0FF0.A9F5.61EE
90EA.BA10.1A77
30BF.C298.A529
50C5.C258.D59A
to cisco
0FF0.A9F5.61EE 0FF0.A9F5.61EE
90EA.BA10.1A77
30BF.C298.A529
50C5.C258.D59A
to microsoft
0F-F0-A9-F5-61-EE 0F-F0-A9-F5-61-EE
90-EA-BA-10-1A-77
30-BF-C2-98-A5-29
50-C5-C2-58-D5-9A
to linux
0F:F0:A9:F5:61:EE 0F:F0:A9:F5:61:EE
90:EA:BA:10:1A:77
30:BF:C2:98:A5:29
50:C5:C2:58:D5:9A
From microsoft
0F-F0-A9-F5-61-EE
90-EA-BA-10-1A-77
30-BF-C2-98-A5-29
50-C5-C2-58-D5-9A
to cisco
0FF0.A9F5.61EE 0FF0.A9F5.61EE
90EA.BA10.1A77
30BF.C298.A529
50C5.C258.D59A
to microsoft
0F-F0-A9-F5-61-EE 0F-F0-A9-F5-61-EE
90-EA-BA-10-1A-77
30-BF-C2-98-A5-29
50-C5-C2-58-D5-9A
to linux
0F:F0:A9:F5:61:EE 0F:F0:A9:F5:61:EE
90:EA:BA:10:1A:77
30:BF:C2:98:A5:29
50:C5:C2:58:D5:9A
From linux
0F:F0:A9:F5:61:EE
90:EA:BA:10:1A:77
30:BF:C2:98:A5:29
50:C5:C2:58:D5:9A
to cisco
0FF0.A9F5.61EE 0FF0.A9F5.61EE
90EA.BA10.1A77
30BF.C298.A529
50C5.C258.D59A
to microsoft
0F-F0-A9-F5-61-EE 0F-F0-A9-F5-61-EE
90-EA-BA-10-1A-77
30-BF-C2-98-A5-29
50-C5-C2-58-D5-9A
to linux
0F:F0:A9:F5:61:EE 0F:F0:A9:F5:61:EE
90:EA:BA:10:1A:77
30:BF:C2:98:A5:29
50:C5:C2:58:D5:9A
Here is my discussion to make this with chatgpt
https://chat.openai.com/share/569fad8b-871a-456b-abe2-310521a6d604
from ditto.
Now, I kind of want to add all the "Line Operations" from Notepad++ to Ditto On Paste scripts !
from ditto.
Related Issues (20)
- Show color of a copied hexode? HOT 5
- Bug with newest nightly 3.24.303 HOT 2
- How can I set the pasted records to be saved permanently? HOT 2
- Paste without copy to clipboard
- Use script in new clip
- In script : clip.SetParentId(<insert group id>); does not work HOT 2
- Pasting directly from a Group folder item HOT 1
- Rebinding RCTRL on Keyboard Manager in Windows Powertoys breaks pasting from GUI HOT 1
- Implement the functionality of smooth scrolling or animated scrolling.
- Request - add in to save all clips used that day in txt file
- [Request] Please add filters for date, type, length, and quick properties.
- [Request] Please add the option to store the copied files (i.e. images, screenshots) in a folder of our choosing.
- autocopy selected text
- Bugs that could be fixed in the next version.
- Paste a line to Excel
- Extra character when pasting into some windows HOT 2
- Indent behavior HOT 5
- Request - add user control of how quickly tooltips to clips popup on screen
- Pin anywhere, not just at the top
- [Request] MacOS support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ditto.