Hi
The code below reads a txt-file that is not saved. The text of this test file is “aa, bb” (paragraph 1… nothing else) and the result when the script is finished is “bb aa”. OK so far.
If I then delete the text from the text-file and paste “cc, dd” the result should be “dd cc”, but I get “bb aa” (paragraph 1) followed by “dd cc” (paragraph 2). Why??? I’m doing something wrong, but can you tell me what it is? The code seems to remember the text from the last run.
property new_source_txt : {}
tell application "TextEdit"
set the source_txt to text of document 1
set AppleScript's text item delimiters to {"," & space}
repeat with i from 1 to (count paragraphs of source_txt)
set the_paragraph to paragraph i of source_txt
try
set {item_1, item_2} to {text item 1 of the_paragraph, text item 2 of the_paragraph}
copy item_2 & space & item_1 & return to the end of new_source_txt
end try
end repeat
set AppleScript's text item delimiters to {""}
set text of document 1 to new_source_txt as string
end tell
Thank You
Pirri