Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FoldingText – Autofocus System
# Autofocus.todo
- item 1
- item 3
# Autofocus.todo
- item 2
tell front document of application "FoldingText"
set itemRecord to startNode of nodeRange of (read selection)
set itemPageRecord to last item of (read nodes at path "//@id=" & |id| of itemRecord & "/ancestor::@type=heading and @line:text=Autofocus")
if (itemPageRecord exists) then
set itemPageID to |id| of itemPageRecord
set itemPagePath to "//@id=" & itemPageID
set lastPageRecord to last item of (read nodes at path "//@id=" & itemPageID & "/parent::*//@type=heading and @line:text=Autofocus")
set lastPagePath to "//@id=" & |id| of lastPageRecord
set lastPageItemCount to 0
if (|id| of lastPageRecord is equal to |id| of itemPageRecord) then
set lastPageRecord to last item of (create nodes at path itemPagePath & "/parent::*" from text return & "# Autofocus.todo")
set lastPagePath to "//@id=" & |id| of lastPageRecord
else
set lastPageItemCount to (count of (read nodes at path lastPagePath & "//*"))
if (lastPageItemCount > 30) then
set lastPageRecord to last item of (create nodes at path itemPagePath & "/parent::*" from text return & "# Autofocus.todo")
set lastPagePath to "//@id=" & |id| of lastPageRecord
end if
end if
if (lastPageItemCount = 0) then
set reenteredItem to last item of (create nodes at path lastPagePath from text return & |line| of itemRecord)
else
set reenteredItem to last item of (create nodes at path lastPagePath from records [itemRecord])
end if
set doneTag to {done:(do shell script "date +'%Y-%m-%d'")}
update nodes at ids [|id| of itemRecord] with changes {addTags:doneTag}
update nodes at ids [|id| of reenteredItem] with changes {removeTags:["done"]}
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment