In a text file given the following text:
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
with AppleScript and BBEdit I'd like to be able to cut the day Sunday
and move it before Monday
but when I reference the BBEdit dictionary I see the ability to cut
:
when I try to cut the text and add it before the line I get an error:
BBEdit got an error: "Sunday" doesn’t understand the “cut” message.
the code:
tell application "BBEdit"
set theFile to "foobar.txt"
select insertion point before first character of text document theFile
repeat
set theWeekend to find "(?<=Saturday\\n)Sunday" searching in text 1 of text document theFile options {search mode:grep} with selecting match
if theWeekend is not found then exit repeat
set theWeekend to found text of theWeekend
select insertion point before first character of text document theFile
set beforeMon to find "(?!<=Sunday\\n)Monday" searching in text 1 of text document theFile options {search mode:grep} with selecting match
if beforeMon is found then
set beforeMon to found text of beforeMon
set theLine to startLine of selection
set addDay to select insertion point before first character of line theLine of text document theFile
set thePull to cut theWeekend ## where error occurs
set before line theLine of text of text document theFile to (theWeekend & return)
end if
end repeat
end tell
If I comment out set thePull to cut theWeekend
the script works in a continuous loop and places Sunday
before Monday
but I can't break the loop because my grep variable theWeekend
is still false
.
Other failed attempts:
cut selection of (theWeekend)
cut theWeekend
cut theWeekend of selection
cut selection of contents of (theWeekend)
cut contents of theWeekend
In BBEdit and AppleScript how can I cut
the day and move it?