Hi,
I wondered if there is a way to change a text from all caps to a regular form text, with capitals at the beginning and lowercase after that, on paste. For example, if the text is "HELLO WORLD" and you copy and paste it, it should turn to "Hello World".
Is something like that possible in BTT?
Thanks
Do you need it on paste or does transforming the selected text also work?
If you just want to transform the selected text you can use this Java Script function with the "transform & replace selection with javascript" actuib
async (clipboardContentString) => {
return clipboardContentString.split(' ') // Split the string into an array of words
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) // Capitalize the first letter of each word
.join(' '); // Join the words back into a string
}
If you need to do it on paste, you need to use the "Run Real Java Script" action. The script get's a bit more complicated and also it's best to update to the latest BTT alpha:
async function someJavaScriptFunction() {
const clipboardContent = await get_clipboard_content();
const transformed = clipboardContent.split(' ') // Split the string into an array of words
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) // Capitalize the first letter of each word
.join(' '); // Join the words back into a string
await paste_text({text: transformed, insert_by_pasting: true});
await set_clipboard_content({content: clipboardContent, format: 'NSPasteboardTypeString'});
return transformed;
}
Hey Andreas,
I tried the version by transforming the selected text, which works like a charm. Thank you for that.
As I thought about it, I will stay with this option since it is more useful than the paste option because you don't always want the uppercase letters to be in lowercase.
I have one more question, and I don't know if I will stick to it. But is it possible to select, for example, a whole paragraph with some uppercase words within and only affect the uppercase letters but not the rest?
I really recommend chatgpt for that kind of stuff
This is the result:
async (clipboardContentString) => {
return clipboardContentString.split(' ') // Split the string into an array of words
.map(word => word === word.toUpperCase() // Check if the word is in uppercase
? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() // Capitalize the first letter, make the rest lowercase
: word) // Leave the word as is if not in uppercase
.join(' '); // Join the words back into a string
}
Hey,
I've done this before for some other coding advice. I think it was something with Apple script, but it didn't work, and my knowledge was not good enough to figure that out, so I gave up.
But I will try that the next time.
Thanks
Apple Script is a bit special, but for pretty much any other programming stuff it is awesome
Ah ok. I see.
Do you have any good sources to learn Apple script?
Because I'm a visual person, I tried to look for some video tutorials but couldn't find anything useful.
Maybe you know any good source for that.
Unfortunately I don't know. I'm also not super good at Apple Script and what I learned I learned over the course of 15 years.
I think the Late Night Software Script Debugger and their forum is very good starting point: http://latenightsw.com
However the question about the future of Apple Script remains. Apple doesn't seem to invest in it anymore.
Oh, really?
I didn't know about that. That is too bad since I have several actions and shortcuts that are based on an Apple script.
Ok, thank you anyway for your help and the link.