AppleScript to create spacing format like "S P A C I N G"? In order to format text documents in a more readable way it would be nice to format selected texts by an apple script executed via the context menu services in the following way:


select "text" with cursor
select context menu/services Spacing (to be created)
selected text is going to be formated to "T E X T"


Does anybody has the knowhow to program such a script?
AppleScript to Expand Text

The following AppleScript snippet adds a space between each character of a string. Copy and paste this code in Applications > Utilities > Script Editor to try it out:

set myText to "hello world"
set myResult to ""

repeat with c in every character in myText
    set myResult to myResult &amp; " " &amp; c
end repeat

display dialog myResult


Automator Service

Using this script, you can use Applications > Automator to create your context menu service.






Launch Automator.app
Create a new workflow, select Service
Add a Run AppleScript action
Copy and paste in the script:

on run {input, parameters}

    set myText to input as string
    set myResult to ""

    repeat with c in every character in myText
        set myResult to ((myResult &amp; " " &amp; c) as string)
    end repeat

    -- Convert to upper case using `tr`
    set myResult to do shell script "echo " &amp; quoted form of (myResult) &amp; " | tr [:lower:] [:upper:]"

    return myResult
end run

Select Output replaces selected text
Save and test your new service