Created
November 14, 2012 21:41
-
-
Save jessegrosjean/4075021 to your computer and use it in GitHub Desktop.
FoldingText – Autofocus System
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Autofocus.todo | |
- item 1 | |
- item 3 | |
# Autofocus.todo | |
- item 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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