I have a lot of text on the file My_Note_Backup.txt
Each time I run an another script, it added to this text something like
demo
demo
{
demo demo demo
demo
}
demo ...
and this repeats around 60 times a day.
How can I have an AppleScript which copies only the last note in between { and }
I have the text delimiter here, but how can I get the most recent text only?
set theName to ""
set theName to the clipboard
set theText to Unicode text
set theSource to theName
property leftEdge1 : "{"
property rightEdge2 : "}"
try
set saveTID to text item delimiters
set text item delimiters to leftEdge1
set classValue to text item 2 of theSource
set text item delimiters to rightEdge2
set theName to text item 1 of classValue
set text item delimiters to saveTID
theName
end try
set the clipboard to theName
the text file is
set dataBackupFile to (path to desktop folder as text) & "My_Note_Backup.txt"
Best Answer
There are a number of options to enable you to run a regex search in Applescript, which is probably the easiest way to do what you're looking for. The below code is written using Satimage, but you can also use any of the other options with the same regex string.
Given the text you provided, this would return:
For completeness sake, I'll just break down the regex:
Edit: I just noticed that your example text has been edited by someone else since you first posted. If you actually meant that it's all on one line separated by spaces, you should replace the
\n
s with spaces.