Created
June 9, 2021 18:39
-
-
Save unsquare/ef107a31c9176ac6138e324e1222af3e to your computer and use it in GitHub Desktop.
AppleScript to change case of clipboard text to uppercase or lowercase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on changeCaseOfText(theText, theCaseToSwitchTo) | |
if theCaseToSwitchTo contains "Lowercase" then | |
set theComparisonCharacters to "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
set theSourceCharacters to "abcdefghijklmnopqrstuvwxyz" | |
else if theCaseToSwitchTo contains "Uppercase" then | |
set theComparisonCharacters to "abcdefghijklmnopqrstuvwxyz" | |
set theSourceCharacters to "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
else | |
return theText | |
end if | |
set theAlteredText to "" | |
repeat with aCharacter in theText | |
set theOffset to offset of aCharacter in theComparisonCharacters | |
if theOffset is not 0 then | |
set theAlteredText to (theAlteredText & character theOffset of theSourceCharacters) as string | |
else | |
set theAlteredText to (theAlteredText & aCharacter) as string | |
end if | |
end repeat | |
return theAlteredText | |
end changeCaseOfText | |
set theDialogText to "Change case of clipboard text?" | |
set userResponse to the button returned of (display dialog theDialogText buttons {"Uppercase", "Lowercase"}) | |
set theString to changeCaseOfText(the clipboard as text, userResponse) | |
set the clipboard to theString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment