在给定以下文本的文本文件中:
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
使用 AppleScript 和 BBEdit 我希望能够缩短这一天Sunday
并在之前移动它,Monday
但是当我参考 BBEdit 字典时,我看到了以下能力cut
:
当我尝试剪切文本并将其添加到行前时,出现错误:
BBEdit 出现错误:“Sunday”不理解“cut”消息。
编码:
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
如果我注释掉set thePull to cut theWeekend
脚本在一个连续循环中工作并放在Sunday
之前Monday
但我不能打破循环,因为我的 grep 变量theWeekend
仍然是false
.
其他失败的尝试:
cut selection of (theWeekend)
cut theWeekend
cut theWeekend of selection
cut selection of contents of (theWeekend)
cut contents of theWeekend
在 BBEdit 和 AppleScript 中,我如何才能cut
在一天中移动它?