Jump to content
Macro Express Forums

Challenge: A macro to change the case of a single word: lowercase --> title case --> uppercase


Recommended Posts

This challenge is a little more challenging than the last one. It's actually kind of hard. Macro Express is probably not the ideal tool for tackling this problem, but the fact that it's do-able in Macro Express is testament to the program's versatility.

 

In Microsoft Word, there is a built-in command called "Case Rotate" that changes text from lowercase to title case, from title case to uppercase, and from uppercase to lowercase. The default hotkey is Shift + F3. This hotkey also works in PowerPoint, and in HTML and RTF email messages in Outlook.

 

The challenge: Use Macro Express to create a case-rotate script that changes the case of the current word. Your macro should work in any application or context where you can type and edit text.

 

Because this challenge is not trivial, I'm suggesting the following constraints that I hope will make solutions easier to achieve:

 

1.    The macro acts on a single word to change its case from lowercase to title case to uppercase. If the text is uppercase, the macro changes the case to lowercase.

2.    The word should NOT be selected! The macro should transform the word where the insertion point (cursor) is located.

3.    The macro should be able to handle punctuation marks that naturally "cling" to words, e.g., commas, periods, question marks, quotation marks, etc. The macro should work equally well for the first word in a document, the last word, or a word in the middle.

4.    The insertion point should be in the same location after the macro has changed the case as it was when the macro was activated. For example, if the cursor was between "e" and "x" in "example" when the macro is activated, the cursor should be in the same spot after the macro has run.

 

I hope you find this challenge as fun as I did.

Link to comment
Share on other sites

It's simple. TT (Text Type) Shift+RightArrow and copy then TT Delete. If the decimal value of the letter is between 97 and 122 subtract 32 else add 32. TT new character and TT ArrowLeft

Link to comment
Share on other sites

  • 3 weeks later...

The solution to this challenge is more challenging to achieve than I anticipated. (When I originally posted it, my solution was flawed. For example, the first and last word of a document must be handled differently than words in the middle.)

 

The difficulties relate to the rules I set out, which I erroneously imagined would simplify matters!

 

 

1.    Rotate a word through three states: lowercase ... Titlecase ... UPPERCASE ... lowercase etc.

2.   The word is NOT selected. This means the macro must somehow capture a word without knowing where the word starts and where the word ends.

3.    After changing the capitalization of the word, the cursor should be in the same location as it was before. When the cursor is in the middle of a word, I needed more code.

4.    This macro should work in any application.

 

 

I abandoned the fourth rule after realizing how different the selection process is in different applications, especially when punctuation and white space (e.g., tabs, spaces, carriage returns) are involved. The selection rules in Notepad are bizarre and unlike other applications. I optimized the script for WordPad, although it seems to work in every application I tried except Notepad.  

 

 

The core idea is that the macro checks characters to see if they are letters or non-letters. Based on inspections of the characters on either side of the cursor, the macro decides whether we are at the start, end, or middle of a word. In outline, here's how the macro works:

 

 

1.    Inspect one character to the left of the cursor.

2.    If the character is nothing, we're at the start of the document/field. Select right one word.

3.    Inspect one character to the right of the cursor.

4.    If the character is nothing, we're at the end of the document/field. Select left one word.

5.    If the characters are letter + non-letter, we're at the end of the word. Select left one word.

6.    If the characters are non-letter + letter, we're at the start of the word. Select right one word.

7.    If the characters are letter + letter, we're in the middle of the word. Select left to the start of the word to determine the position within the word. Then select right one word.

8.    If the characters are non-letter + non-letter, take an educated guess: try to select the current word.

9.    Transform the capitalization of the selected word. (Handled by a separate, called macro.)

 

 

I'm not claiming this solution is practical. It works (although not reliably in Notepad), but it's a bit clunky. I've made an AutoHotkey script that does the same thing, and it executes almost instantly. But this has been a fun Macro Express project.

 

If you have a simpler way to case rotate an unselected word using Macro Express, please post your solution!

 

=========================
Main script:
=========================

Variable Set String %Letters% to "abcdefghijklmnopqrstuvwxyz"
 
// Capture character to left
Clipboard Empty
Text Type (Simulate Keystrokes): <SHIFT><ARROW LEFT><CONTROL>c
Variable Set String %CharLeft% from the clipboard contents
 
// We must be at the start of the document/field
If Variable %CharLeft% Equals ""
  Text Type (Simulate Keystrokes): <CONTROL><SHIFT><ARROW RIGHT><CONTROL>c
  Macro Run: Capitalize Engine
  // Restore cursor position
  Text Type (Simulate Keystrokes): <CONTROL><ARROW LEFT>
  Macro Stop
End If
 
// Capture character to right
Clipboard Empty
Text Type (Simulate Keystrokes): <ARROW RIGHT><SHIFT><ARROW RIGHT><CONTROL>c
Variable Set String %CharRight% from the clipboard contents
 
// We must be at the end of the document/field
If Variable %CharRight% Equals ""
  Text Type (Simulate Keystrokes): <ARROW RIGHT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c
  Macro Run: Capitalize Engine
  // Restore cursor position (nothing to do)
  Macro Stop
End If
 
// Left = Non-letter and Right = Alpha
If Variable %Letters% Does not Contain "%CharLeft%"
  AND
If Variable %Letters% Contains "%CharRight%"
  Text Type (Simulate Keystrokes): <ARROW LEFT><CONTROL><SHIFT><ARROW RIGHT><CONTROL>c
  Macro Run: Capitalize Engine
  // Restore cursor position (move left one word)
  Text Type (Simulate Keystrokes): <CONTROL><ARROW LEFT>
  Macro Stop
End If
 
// Left = Letter and Right = Non-letter
If Variable %Letters% Contains "%CharLeft%"
  AND
If Variable %Letters% Does not Contain "%CharRight%"
  Text Type (Simulate Keystrokes): <ARROW LEFT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c
  Macro Run: Capitalize Engine
  // Restore cursor position (nothing to do)
  Macro Stop
End If
 
// Left = Letter and Right = Letter
If Variable %Letters% Contains "%CharLeft%"
  AND
If Variable %Letters% Contains "%CharRight%"
  Text Type (Simulate Keystrokes): <ARROW RIGHT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c
  Variable Set String %WordLeft% from the clipboard contents
  Variable Set Integer %Offset% to the length of variable %WordLeft%
  Variable Modify Integer: %Offset% = %Offset% - 1
  Text Type (Simulate Keystrokes): <ARROW RIGHT><CONTROL><ARROW LEFT><SHIFT><CONTROL><ARROW RIGHT><CONTROL>c
  Macro Run: Capitalize Engine
  // Restore cursor position (from start of word, move right to the initial position within the word)
  Text Type (Simulate Keystrokes): <CONTROL><ARROW LEFT>
  Repeat Start (Repeat %Offset% times)
    Text Type (Simulate Keystrokes): <ARROW RIGHT>
  End Repeat
  Macro Stop
End If
 
// Left = Non-letter and Right = Non-letter
If Variable %Letters% Does not Contain "%CharLeft%"
  AND
If Variable %Letters% Does not Contain "%CharRight%"
  Text Type (Simulate Keystrokes): <ARROW LEFT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c
  Macro Run: Capitalize Engine
  // Restore cursor position (nothing to do)
  Macro Stop
End If
 
// Unknown
Text Type (Simulate Keystrokes): <ARROW LEFT>
Text Box Display: This situation is not handled!
Macro Stop

=========================
Capitalize Engine:
=========================
  
Variable Set String %Word% from the clipboard contents
 
Variable Set String %WordUpperCase% to "%Word%"
Variable Set String %WordLowerCase% to "%Word%"
Variable Modify String %WordUpperCase%: Uppercase
Variable Modify String %WordLowerCase%: Lowercase
 
If Variable %WordUpperCase% Equals "%Word%" // Change uppercase to lowercase
  Text Type (Simulate Keystrokes): %WordLowerCase%
Else
  If Variable %WordLowerCase% Equals "%Word%" // Change lowercase to title case
    Variable Set Integer %WordLength% to the length of variable %Word%
    Variable Modify String: Copy part of text in %Word% starting at 1 and 1 characters long to %FirstChar%
    Variable Modify String %FirstChar%: Uppercase
    Variable Modify String: Copy part of text in %Word% starting at 2 and %WordLength% characters long to %AllButFirstChar%
    Variable Modify String %AllButFirstChar%: Lowercase
    Text Type (Simulate Keystrokes): %FirstChar%%AllButFirstChar%
  Else
    Text Type (Simulate Keystrokes): %WordUpperCase%
  End If
End If

 

=========================
Main script:
=========================
<VARIABLE SET STRING Option="\x00" Destination="%Letters%" Value="abcdefghijklmnopqrstuvwxyz" NoEmbeddedVars="FALSE"/>
<COMMENT/>
<COMMENT Value="Capture character to left"/>
<CLIPBOARD EMPTY/>
<TEXT TYPE Action="0" Text="<SHIFT><ARROW LEFT><CONTROL>c"/>
<VARIABLE SET STRING Option="\x02" Destination="%CharLeft%" NoEmbeddedVars="FALSE"/>
<COMMENT/>
<COMMENT Value="We must be at the start of the document/field"/>
<IF VARIABLE Variable="%CharLeft%" Condition="\x00" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="<CONTROL><SHIFT><ARROW RIGHT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position" _BACK="0080FFFF"/>
<TEXT TYPE Action="0" Text="<CONTROL><ARROW LEFT>"/>
<MACRO STOP/>
<END IF/>
<COMMENT/>
<COMMENT Value="Capture character to right"/>
<CLIPBOARD EMPTY/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT><SHIFT><ARROW RIGHT><CONTROL>c"/>
<VARIABLE SET STRING Option="\x02" Destination="%CharRight%" NoEmbeddedVars="FALSE"/>
<COMMENT/>
<COMMENT Value="We must be at the end of the document/field"/>
<IF VARIABLE Variable="%CharRight%" Condition="\x00" IgnoreCase="TRUE"/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position (nothing to do)" _BACK="0080FFFF"/>
<MACRO STOP/>
<END IF/>
<COMMENT/>
<COMMENT Value="Left = Non-letter and Right = Alpha"/>
<IF VARIABLE Variable="%Letters%" Condition="\x07" Value="%CharLeft%" IgnoreCase="TRUE"/>
<AND/>
<IF VARIABLE Variable="%Letters%" Condition="\x06" Value="%CharRight%" IgnoreCase="TRUE"/>
<TEXT TYPE Action="0" Text="<ARROW LEFT><CONTROL><SHIFT><ARROW RIGHT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position (move left one word)" _BACK="0080FFFF"/>
<TEXT TYPE Action="0" Text="<CONTROL><ARROW LEFT>"/>
<MACRO STOP/>
<END IF/>
<COMMENT/>
<COMMENT Value="Left = Letter and Right = Non-letter"/>
<IF VARIABLE Variable="%Letters%" Condition="\x06" Value="%CharLeft%" IgnoreCase="TRUE"/>
<AND/>
<IF VARIABLE Variable="%Letters%" Condition="\x07" Value="%CharRight%" IgnoreCase="TRUE"/>
<TEXT TYPE Action="0" Text="<ARROW LEFT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position (nothing to do)"/>
<MACRO STOP/>
<END IF/>
<COMMENT/>
<COMMENT Value="Left = Letter and Right = Letter"/>
<IF VARIABLE Variable="%Letters%" Condition="\x06" Value="%CharLeft%" IgnoreCase="TRUE"/>
<AND/>
<IF VARIABLE Variable="%Letters%" Condition="\x06" Value="%CharRight%" IgnoreCase="TRUE"/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c"/>
<VARIABLE SET STRING Option="\x02" Destination="%WordLeft%" NoEmbeddedVars="FALSE"/>
<VARIABLE SET INTEGER Option="\x0D" Destination="%Offset%" Text_Variable="%WordLeft%"/>
<VARIABLE MODIFY INTEGER Option="\x01" Destination="%Offset%" Value1="%Offset%" Value2="1"/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT><CONTROL><ARROW LEFT><SHIFT><CONTROL><ARROW RIGHT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position (from start of word, move right to the initial position within the word)" _BACK="0080FFFF"/>
<TEXT TYPE Action="0" Text="<CONTROL><ARROW LEFT>"/>
<REPEAT START Start="1" Step="1" Count="%Offset%" Save="FALSE"/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT>"/>
<END REPEAT/>
<MACRO STOP/>
<END IF/>
<COMMENT/>
<COMMENT Value="Left = Non-letter and Right = Non-letter"/>
<IF VARIABLE Variable="%Letters%" Condition="\x07" Value="%CharLeft%" IgnoreCase="TRUE"/>
<AND/>
<IF VARIABLE Variable="%Letters%" Condition="\x07" Value="%CharRight%" IgnoreCase="TRUE"/>
<TEXT TYPE Action="0" Text="<ARROW LEFT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position (nothing to do)" _BACK="0080FFFF"/>
<MACRO STOP/>
<END IF/>
<COMMENT/>
<COMMENT Value="Unknown"/>
<TEXT TYPE Action="0" Text="<ARROW LEFT>"/>
<TEXT BOX DISPLAY Title="This situation is not handled!" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs20 L: [%CharLeft%]\r\n\\par R: [%CharRight%]\r\n\\par \\lang1033\\f1\\fs14 \r\n\\par \\lang4105\\f0\\fs20 Ascii L: [%AsciiCharLeft%]\r\n\\par Ascii R: [%AsciiCharRight%]\r\n\\par \\lang1033\\f1\\fs14 \r\n\\par \r\n\\par }\r\n" Left="821" Top="417" Width="395" Height="338" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<MACRO STOP/>

=========================
Capitalize Engine:
=========================

<VARIABLE SET STRING Option="\x02" Destination="%Word%" NoEmbeddedVars="FALSE"/>
<COMMENT/>
<VARIABLE SET STRING Option="\x00" Destination="%WordUpperCase%" Value="%Word%" NoEmbeddedVars="FALSE"/>
<VARIABLE SET STRING Option="\x00" Destination="%WordLowerCase%" Value="%Word%" NoEmbeddedVars="FALSE"/>
<VARIABLE MODIFY STRING Option="\x0B" Destination="%WordUpperCase%"/>
<VARIABLE MODIFY STRING Option="\x0C" Destination="%WordLowerCase%"/>
<COMMENT/>
<IF VARIABLE Variable="%WordUpperCase%" Condition="\x00" Value="%Word%" IgnoreCase="FALSE" _COMMENT="Change uppercase to lowercase"/>
<TEXT TYPE Action="0" Text="%WordLowerCase%"/>
<ELSE/>
<IF VARIABLE Variable="%WordLowerCase%" Condition="\x00" Value="%Word%" IgnoreCase="FALSE" _COMMENT="Change lowercase to title case"/>
<VARIABLE SET INTEGER Option="\x0D" Destination="%WordLength%" Text_Variable="%Word%"/>
<VARIABLE MODIFY STRING Option="\x09" Destination="%FirstChar%" Variable="%Word%" Start="1" Count="1" NoEmbeddedVars="FALSE"/>
<VARIABLE MODIFY STRING Option="\x0B" Destination="%FirstChar%"/>
<VARIABLE MODIFY STRING Option="\x09" Destination="%AllButFirstChar%" Variable="%Word%" Start="2" Count="%WordLength%" NoEmbeddedVars="FALSE"/>
<VARIABLE MODIFY STRING Option="\x0C" Destination="%AllButFirstChar%"/>
<TEXT TYPE Action="0" Text="%FirstChar%%AllButFirstChar%"/>
<ELSE/>
<TEXT TYPE Action="0" Text="%WordUpperCase%"/>
<END IF/>
<END IF/>
<COMMENT/>

 

Link to comment
Share on other sites

I've enhanced the main script. (The "Capitalize Engine" script is the same. See code in previous message.) Updates:

 

1. This version is less "flashy" -- text is selected and de-selected more quickly.

 

2. It runs a little faster.

 

3. This version checks for non-letters that "cling" to words, like commas, colons, open and close quotes, question marks, etc., and makes an educated guess on which word to case-rotate.

 

4. Although the original challenge was to case rotate an unselected word, this script acts on the first word in a selection.

 

It would be nice if the script were to act on every word in a selection, but that's not something I plan to take on. Maybe it can be done with RegEx??

 

// Case-rotate an unselected word: lowercase ... Titlecase ... UPPERCASE ... back to lowercase ... etc. 
// The cursor returns to its pre-capitalized location.
 
// LIMITATIONS:
// 1. Unreliable in Notepad when non-letters cling to words: Hello. "Hello" Hello! etc.
// 2. Doesn't handle "non-standard" punctuation, symbols, and spacing.
// 3. Runs a bit slowly!
// 4. Although not intended for selections, the macro will act on the first word in a block of text.
 
// HOW IT WORKS:
// 0. Check if text is selected. If yes, de-select and act on first word.
// 1. Inspect one character to the left of the cursor, and one character to the right of the cursor.
// 2. If the left character = "", the cursor is at the start of the document/field. Select right one word.
// 3. If the right character = "", the cursor is at the end of the document/field. Select left one word.
// 4. If Letter + Letter, the cursor is in the middle of the word. 
//     Select left to start of the word to determine cursor position. Then select right one word.
// 5. If Letter + Non-letter, the cursor is at the end of the word. Select left one word.
// 6. If Non-letter + Letter, the cursor is at the start of the word. Select right one word.
// 7. If Non-letter + Non-letter, take a guess which word to select based on normal punctuation rules. 
// 8. Transform the capitalization of the selected word. (Handled by a separate, called macro.)
 
// Check if text is selected. If yes, de-select and act on first word in the selection.
Clipboard Empty
Text Type (Simulate Keystrokes): <CONTROL>c
Variable Set String %Clip% from the clipboard contents
Variable Set Integer %ClipLength% to the length of variable %Clip%
If Variable %ClipLength% Is Greater Than "0"
  Text Type (Simulate Keystrokes): <ARROW LEFT><CONTROL><ARROW RIGHT>
End If
 
// Inspect character to left
Clipboard Empty
Text Type (Simulate Keystrokes): <SHIFT><ARROW LEFT><CONTROL>c<ARROW RIGHT>
Variable Set String %CharLeft% from the clipboard contents
 
// Inspect character to right
Clipboard Empty
Text Type (Simulate Keystrokes): <SHIFT><ARROW RIGHT><CONTROL>c<ARROW LEFT>
Variable Set String %CharRight% from the clipboard contents
 
// Cursor is at the start of the document/field?
If Variable %CharLeft% Equals ""
  Text Type (Simulate Keystrokes): <ARROW LEFT><CONTROL><SHIFT><ARROW RIGHT><CONTROL>c
  Macro Run: Capitalize Engine
  // Restore cursor position
  Text Type (Simulate Keystrokes): <CONTROL><ARROW LEFT>
  Macro Stop
End If
 
// Cursor is at the end of the document/field?
If Variable %CharRight% Equals ""
  Text Type (Simulate Keystrokes): <ARROW RIGHT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c
  Macro Run: Capitalize Engine
  // Restore cursor position (nothing to do)
  Macro Stop
End If
 
Variable Set String %Letters% to "abcdefghijklmnopqrstuvwxyz"
 
// Cursor is in the middle of a word? (Letter + Letter)
If Variable %Letters% Contains "%CharLeft%"
  AND
If Variable %Letters% Contains "%CharRight%"
  Text Type (Simulate Keystrokes): <ARROW RIGHT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c<ARROW LEFT>
  Variable Set String %WordLeft% from the clipboard contents
  Variable Set Integer %Offset% to the length of variable %WordLeft%
  Variable Modify Integer: %Offset% = %Offset% - 1
  Text Type (Simulate Keystrokes): <SHIFT><CONTROL><ARROW RIGHT><CONTROL>c
  Macro Run: Capitalize Engine
  // Restore cursor position (from start of word, move right to the initial position within the word)
  Text Type (Simulate Keystrokes): <CONTROL><ARROW LEFT>
  Repeat Start (Repeat %Offset% times)
    Text Type (Simulate Keystrokes): <ARROW RIGHT>
  End Repeat
  Macro Stop
End If
 
// Cursor is at the start of a word? (Non-letter + Letter)
If Variable %Letters% Does not Contain "%CharLeft%"
  AND
If Variable %Letters% Contains "%CharRight%"
  Text Type (Simulate Keystrokes): <CONTROL><SHIFT><ARROW RIGHT><CONTROL>c
  Macro Run: Capitalize Engine
  // Restore cursor position
  Text Type (Simulate Keystrokes): <CONTROL><ARROW LEFT>
  Macro Stop
End If
 
// Cursor is at the end of a word? (Letter + Non-letter)
If Variable %Letters% Contains "%CharLeft%"
  AND
If Variable %Letters% Does not Contain "%CharRight%"
  Text Type (Simulate Keystrokes): <CONTROL><SHIFT><ARROW LEFT><CONTROL>c
  Macro Run: Capitalize Engine
  // Restore cursor position (nothing to do)
  Macro Stop
End If
 
// Cursor is in an ambigous location? (Non-letter + Non-letter)
If Variable %Letters% Does not Contain "%CharLeft%"
  AND
If Variable %Letters% Does not Contain "%CharRight%"
// Make a guess which word to act upon based on normal punctuation rules.
  Variable Set String %Punc% to ",./<>?;:'"[{]}!@#$%^&*()-_=+\|"
   
  // If %CharLeft% is punctuation, act on previous word
  If Variable %Punc% Contains "%CharLeft%"
    Text Type (Simulate Keystrokes): <ARROW LEFT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c
    Macro Run: Capitalize Engine
    // Restore cursor position
    Text Type (Simulate Keystrokes): <ARROW RIGHT>
    Macro Stop
  End If
   
  // If %CharRight% is punctuation, act on next word
  If Variable %Punc% Contains "%CharRight%"
    Text Type (Simulate Keystrokes): <ARROW RIGHT><CONTROL><SHIFT><ARROW RIGHT><CONTROL>c
    Macro Run: Capitalize Engine
    // Restore cursor position
    Text Type (Simulate Keystrokes): <CONTROL><ARROW LEFT><ARROW LEFT>
  End If
  Macro Stop
End If
 

<COMMENT Value="Case-rotate an unselected word: lowercase ... Titlecase ... UPPERCASE ... back to lowercase ... etc. "/>
<COMMENT Value="The cursor returns to its pre-capitalized location."/>
<COMMENT/>
<COMMENT Value="LIMITATIONS:" _BACK="0080FFFF"/>
<COMMENT Value="1. Unreliable in Notepad when non-letters cling to words: Hello. \"Hello\" Hello! etc."/>
<COMMENT Value="2. Doesn't handle \"non-standard\" punctuation, symbols, and spacing."/>
<COMMENT Value="3. Runs a bit slowly!"/>
<COMMENT Value="4. Although not intended for selections, the macro will act on the first word in a block of text."/>
<COMMENT/>
<COMMENT Value="HOW IT WORKS:" _BACK="0080FFFF"/>
<COMMENT Value="0. Check if text is selected. If yes, de-select and act on first word."/>
<COMMENT Value="1. Inspect one character to the left of the cursor, and one character to the right of the cursor."/>
<COMMENT Value="2. If the left character = \"\", the cursor is at the start of the document/field. Select right one word."/>
<COMMENT Value="3. If the right character = \"\", the cursor is at the end of the document/field. Select left one word."/>
<COMMENT Value="4. If Letter + Letter, the cursor is in the middle of the word. "/>
<COMMENT Value="    Select left to start of the word to determine cursor position. Then select right one word."/>
<COMMENT Value="5. If Letter + Non-letter, the cursor is at the end of the word. Select left one word."/>
<COMMENT Value="6. If Non-letter + Letter, the cursor is at the start of the word. Select right one word."/>
<COMMENT Value="7. If Non-letter + Non-letter, take a guess which word to select based on normal punctuation rules. "/>
<COMMENT Value="8. Transform the capitalization of the selected word. (Handled by a separate, called macro.)"/>
<COMMENT/>
<COMMENT Value="Check if text is selected. If yes, de-select and act on first word in the selection."/>
<CLIPBOARD EMPTY/>
<TEXT TYPE Action="0" Text="<CONTROL>c"/>
<VARIABLE SET STRING Option="\x02" Destination="%Clip%" NoEmbeddedVars="FALSE"/>
<VARIABLE SET INTEGER Option="\x0D" Destination="%ClipLength%" Text_Variable="%Clip%"/>
<IF VARIABLE Variable="%ClipLength%" Condition="\x03" Value="0" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="<ARROW LEFT><CONTROL><ARROW RIGHT>"/>
<END IF/>
<COMMENT/>
<COMMENT Value="Inspect character to left"/>
<CLIPBOARD EMPTY/>
<TEXT TYPE Action="0" Text="<SHIFT><ARROW LEFT><CONTROL>c<ARROW RIGHT>"/>
<VARIABLE SET STRING Option="\x02" Destination="%CharLeft%" NoEmbeddedVars="FALSE"/>
<COMMENT/>
<COMMENT Value="Inspect character to right"/>
<CLIPBOARD EMPTY/>
<TEXT TYPE Action="0" Text="<SHIFT><ARROW RIGHT><CONTROL>c<ARROW LEFT>"/>
<VARIABLE SET STRING Option="\x02" Destination="%CharRight%" NoEmbeddedVars="FALSE"/>
<COMMENT/>
<COMMENT Value="Cursor is at the start of the document/field?"/>
<IF VARIABLE Variable="%CharLeft%" Condition="\x00" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="<ARROW LEFT><CONTROL><SHIFT><ARROW RIGHT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position" _BACK="0080FFFF"/>
<TEXT TYPE Action="0" Text="<CONTROL><ARROW LEFT>"/>
<MACRO STOP/>
<END IF/>
<COMMENT/>
<COMMENT Value="Cursor is at the end of the document/field?"/>
<IF VARIABLE Variable="%CharRight%" Condition="\x00" IgnoreCase="TRUE"/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position (nothing to do)" _BACK="0080FFFF"/>
<MACRO STOP/>
<END IF/>
<COMMENT/>
<VARIABLE SET STRING Option="\x00" Destination="%Letters%" Value="abcdefghijklmnopqrstuvwxyz" NoEmbeddedVars="FALSE"/>
<COMMENT/>
<COMMENT Value="Cursor is in the middle of a word? (Letter + Letter)"/>
<IF VARIABLE Variable="%Letters%" Condition="\x06" Value="%CharLeft%" IgnoreCase="TRUE"/>
<AND/>
<IF VARIABLE Variable="%Letters%" Condition="\x06" Value="%CharRight%" IgnoreCase="TRUE"/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c<ARROW LEFT>"/>
<VARIABLE SET STRING Option="\x02" Destination="%WordLeft%" NoEmbeddedVars="FALSE"/>
<VARIABLE SET INTEGER Option="\x0D" Destination="%Offset%" Text_Variable="%WordLeft%"/>
<VARIABLE MODIFY INTEGER Option="\x01" Destination="%Offset%" Value1="%Offset%" Value2="1"/>
<TEXT TYPE Action="0" Text="<SHIFT><CONTROL><ARROW RIGHT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position (from start of word, move right to the initial position within the word)" _BACK="0080FFFF"/>
<TEXT TYPE Action="0" Text="<CONTROL><ARROW LEFT>"/>
<REPEAT START Start="1" Step="1" Count="%Offset%" Save="FALSE"/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT>"/>
<END REPEAT/>
<MACRO STOP/>
<END IF/>
<COMMENT/>
<COMMENT Value="Cursor is at the start of a word? (Non-letter + Letter)"/>
<IF VARIABLE Variable="%Letters%" Condition="\x07" Value="%CharLeft%" IgnoreCase="TRUE"/>
<AND/>
<IF VARIABLE Variable="%Letters%" Condition="\x06" Value="%CharRight%" IgnoreCase="TRUE"/>
<TEXT TYPE Action="0" Text="<CONTROL><SHIFT><ARROW RIGHT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position" _BACK="0080FFFF"/>
<TEXT TYPE Action="0" Text="<CONTROL><ARROW LEFT>"/>
<MACRO STOP/>
<END IF/>
<COMMENT/>
<COMMENT Value="Cursor is at the end of a word? (Letter + Non-letter)"/>
<IF VARIABLE Variable="%Letters%" Condition="\x06" Value="%CharLeft%" IgnoreCase="TRUE"/>
<AND/>
<IF VARIABLE Variable="%Letters%" Condition="\x07" Value="%CharRight%" IgnoreCase="TRUE"/>
<TEXT TYPE Action="0" Text="<CONTROL><SHIFT><ARROW LEFT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position (nothing to do)" _BACK="0080FFFF"/>
<MACRO STOP/>
<END IF/>
<COMMENT/>
<COMMENT Value="Cursor is in an ambigous location? (Non-letter + Non-letter)"/>
<IF VARIABLE Variable="%Letters%" Condition="\x07" Value="%CharLeft%" IgnoreCase="TRUE"/>
<AND/>
<IF VARIABLE Variable="%Letters%" Condition="\x07" Value="%CharRight%" IgnoreCase="TRUE"/>
<COMMENT Value="Make a guess which word to act upon based on normal punctuation rules."/>
<VARIABLE SET STRING Option="\x00" Destination="%Punc%" Value=",./<>?;:'\"[{]}!@#$%^&*()-_=+\\|" NoEmbeddedVars="TRUE"/>
<COMMENT/>
<COMMENT Value="If %CharLeft% is punctuation, act on previous word"/>
<IF VARIABLE Variable="%Punc%" Condition="\x06" Value="%CharLeft%" IgnoreCase="TRUE"/>
<TEXT TYPE Action="0" Text="<ARROW LEFT><CONTROL><SHIFT><ARROW LEFT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position" _BACK="0080FFFF"/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT>"/>
<MACRO STOP/>
<END IF/>
<COMMENT/>
<COMMENT Value="If %CharRight% is punctuation, act on next word"/>
<IF VARIABLE Variable="%Punc%" Condition="\x06" Value="%CharRight%" IgnoreCase="TRUE"/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT><CONTROL><SHIFT><ARROW RIGHT><CONTROL>c"/>
<MACRO RUN Use_ID="FALSE" Name="Capitalize Engine" ID="-1" Wait="TRUE"/>
<COMMENT Value="Restore cursor position" _BACK="0080FFFF"/>
<TEXT TYPE Action="0" Text="<CONTROL><ARROW LEFT><ARROW LEFT>"/>
<END IF/>
<MACRO STOP/>
<END IF/>
<COMMENT/>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...