substitution script

Trying to automate some music work for school. Would it be possible to get an applescript to do this.

So say I had some text :

DE|F2 F2 F2 EF|A2 A2 B2 AF

I want an applescript to change that to this :

"D"D"E"E| "F"F2 "F"F2 "F"F2 "E"E"F"F |"A"A2 "A"A2 "B"B2 "A"A"F"F

I think this is possible but I’m just trying to get my head round how to do it. Any assistance would be appreciated

Hi.

What sort of music is that!? :confused:

Assuming that the letters are note names and that they’re always in the upper case, the change could be effected easily ” albeit wordily ” with vanilla AppleScript like this:

set someText to "DE|F2 F2 F2 EF|A2 A2 B2 AF"

set newText to someText
set astid to AppleScript's text item delimiters
repeat with thisNote in "ABCDEFG"
	set AppleScript's text item delimiters to thisNote's contents
	set newText to newText's text items
	set AppleScript's text item delimiters to quote & thisNote & quote & thisNote
	set newText to newText as text
end repeat
set AppleScript's text item delimiters to astid

display dialog newText

A shorter alternative would be to use “sed” in a shell script:

set someText to "DE|F2 F2 F2 EF|A2 A2 B2 AF"

set newText to (do shell script ("<<< " & quoted form of someText & " sed 's/[A-G]/\"&\"&/g'"))

display dialog newText