- [Mastodon](https://mastodon.social/@DavidBlue/113417837332892729)
Thanks to Google Gemini, I created an Action for @drafts that converts currently-selected text to ꜱᴍᴀʟʟ ᴄᴀᴘꜱ. https://directory.getdrafts.com/a/2VW
## Meta
### Description
Convert the current text selection to ꜱᴍᴀʟʟ ᴄᴀᴘꜱ case.
### Directory Description
Convert the current text selection to [ꜱᴍᴀʟʟ ᴄᴀᴘꜱ case](https://en.wikipedia.org/wiki/Small_caps).
---
## Babylon
### Prompt:
> I'd like to create an Action for Drafts (getdrafts.com) which transforms the currently selected text (selection_only) into small caps.
### Initial Response
Absolutely! I can help you create a Drafts action that transforms selected text into small caps. Here's how we can approach this:
##### Understanding the request
- You want an action for the Drafts application.
- The action should convert any selected text to small caps.
- If no text is selected, it should presumably do nothing.
##### Overview of the solution
We'll use the Drafts scripting API to:
1. Get the currently selected text.
2. If there is no selection, exit.
3. Convert the selected text to small caps.
4. Replace the selection in the editor with the converted text.
##### The code
```js
// Get the currently selected text.
let selection = editor.getSelectedText();
// If there is no selection, exit.
if (!selection) {
context.cancel();
}
// Convert the selection to small caps.
let smallCapsText = selection.toLowerCase();
// Replace the selection with the small caps text.
editor.setSelectedText(smallCapsText);
```
##### Implementation instructions
1. Open the Drafts application on your device.
2. Create a new action.
3. In the action editor, select "Javascript" as the action step type.
4. Copy and paste the code above into the code editor.
5. Save the action with a descriptive name, like "Small Caps".
6. Select some text in a draft and run the action. The selected text should now be in small caps.
##### Additional notes
- This action will only work on the selected text. If you want to convert the entire draft to small caps, you'll need to modify the code to get the entire draft content instead of just the selection.
- You can customize the action further by adding options to control the case of the converted text, such as uppercase or title case.
- Remember to test the action thoroughly to make sure it works as expected.
I hope this helps! Let me know if you have any other questions or need further assistance.
### Correction Prompt:
> No, small caps like this: sᴍᴀʟʟ ᴄᴀᴘs
### Corrected Response
Ah, I understand! You'd like to use the Unicode small caps characters like sᴍᴀʟʟ ᴄᴀᴘs.
Here's the updated code:
```js
// Get the currently selected text.
let selection = editor.getSelectedText();
// If there is no selection, exit.
if (!selection) {
context.cancel();
}
// Convert the selection to small caps.
let smallCapsText = selection.toLowerCase().replace(/[a-z]/g, function(char) {
switch (char) {
case 'a': return 'ᴀ';
case 'b': return 'ʙ';
case 'c': return 'ᴄ';
case 'd': return 'ᴅ';
case 'e': return 'ᴇ';
case 'f': return 'ꜰ';
case 'g': return 'ɢ';
case 'h': return 'ʜ';
case 'i': return 'ɪ';
case 'j': return 'ᴊ';
case 'k': return 'ᴋ';
case 'l': return 'ʟ';
case 'm': return 'ᴍ';
case 'n': return 'ɴ';
case 'o': return 'ᴏ';
case 'p': return 'ᴘ';
case 'q': return 'ǫ';
case 'r': return 'ʀ';
case 's': return 'ꜱ';
case 't': return 'ᴛ';
case 'u': return 'ᴜ';
case 'v': return 'ᴠ';
case 'w': return 'ᴡ';
case 'x': return 'x';
case 'y': return 'ʏ';
case 'z': return 'ᴢ';
default: return char;
}
});
// Replace the selection with the small caps text.
editor.setSelectedText(smallCapsText);
```
This script now iterates through each character in the selected text and replaces it with its corresponding Unicode small caps equivalent.
The implementation instructions remain the same. Just replace the previous code with this updated version in your Drafts action.
##### Sources
1. ](https://github.com/dtmorrow/MyLibs) subject to license (Unlicense)
2. ](https://github.com/devho813/ros-ranking)
Updated
11032024-012821
40BC6A91-D4D1-4630-9AFB-D6DAE113BF7C
Social
- [Mastodon](https://mastodon.social/@DavidBlue/113417837332892729) Thanks to Google Gemini, I created an Action for @drafts that converts currently-selected text to ꜱᴍᴀʟʟ ᴄᴀᴘꜱ. https://directory.getdrafts.com/a/2VW ## Meta ### Description Convert the current text selection to ꜱᴍᴀʟʟ ᴄᴀᴘꜱ case. ### Directory Description Convert the current text selection to [ꜱᴍᴀʟʟ ᴄᴀᴘꜱ case](https://en.wikipedia.org/wiki/Small_caps). --- ## Babylon ### Prompt: > I'd like to create an Action for Drafts (getdrafts.com) which transforms the currently selected text (selection_only) into small caps. ### Initial Response Absolutely! I can help you create a Drafts action that transforms selected text into small caps. Here's how we can approach this: ##### Understanding the request - You want an action for the Drafts application. - The action should convert any selected text to small caps. - If no text is selected, it should presumably do nothing. ##### Overview of the solution We'll use the Drafts scripting API to: 1. Get the currently selected text. 2. If there is no selection, exit. 3. Convert the selected text to small caps. 4. Replace the selection in the editor with the converted text. ##### The code ```js // Get the currently selected text. let selection = editor.getSelectedText(); // If there is no selection, exit. if (!selection) { context.cancel(); } // Convert the selection to small caps. let smallCapsText = selection.toLowerCase(); // Replace the selection with the small caps text. editor.setSelectedText(smallCapsText); ``` ##### Implementation instructions 1. Open the Drafts application on your device. 2. Create a new action. 3. In the action editor, select "Javascript" as the action step type. 4. Copy and paste the code above into the code editor. 5. Save the action with a descriptive name, like "Small Caps". 6. Select some text in a draft and run the action. The selected text should now be in small caps. ##### Additional notes - This action will only work on the selected text. If you want to convert the entire draft to small caps, you'll need to modify the code to get the entire draft content instead of just the selection. - You can customize the action further by adding options to control the case of the converted text, such as uppercase or title case. - Remember to test the action thoroughly to make sure it works as expected. I hope this helps! Let me know if you have any other questions or need further assistance. ### Correction Prompt: > No, small caps like this: sᴍᴀʟʟ ᴄᴀᴘs ### Corrected Response Ah, I understand! You'd like to use the Unicode small caps characters like sᴍᴀʟʟ ᴄᴀᴘs. Here's the updated code: ```js // Get the currently selected text. let selection = editor.getSelectedText(); // If there is no selection, exit. if (!selection) { context.cancel(); } // Convert the selection to small caps. let smallCapsText = selection.toLowerCase().replace(/[a-z]/g, function(char) { switch (char) { case 'a': return 'ᴀ'; case 'b': return 'ʙ'; case 'c': return 'ᴄ'; case 'd': return 'ᴅ'; case 'e': return 'ᴇ'; case 'f': return 'ꜰ'; case 'g': return 'ɢ'; case 'h': return 'ʜ'; case 'i': return 'ɪ'; case 'j': return 'ᴊ'; case 'k': return 'ᴋ'; case 'l': return 'ʟ'; case 'm': return 'ᴍ'; case 'n': return 'ɴ'; case 'o': return 'ᴏ'; case 'p': return 'ᴘ'; case 'q': return 'ǫ'; case 'r': return 'ʀ'; case 's': return 'ꜱ'; case 't': return 'ᴛ'; case 'u': return 'ᴜ'; case 'v': return 'ᴠ'; case 'w': return 'ᴡ'; case 'x': return 'x'; case 'y': return 'ʏ'; case 'z': return 'ᴢ'; default: return char; } }); // Replace the selection with the small caps text. editor.setSelectedText(smallCapsText); ``` This script now iterates through each character in the selected text and replaces it with its corresponding Unicode small caps equivalent. The implementation instructions remain the same. Just replace the previous code with this updated version in your Drafts action. ##### Sources 1.