Question:
I use a script that adds strikethrough and a @done(YYYY-MM-DD) “tag”. I think it’s posted on the Bike Extensions wiki, though I did use ChatGPT to translate that thing to AppleScript. Anyway, the original script doesn’t seem to apply any specific attribute to the row, just formats the text and appends the @done tag.
I have now replaced that script to toggle the “done” attribute and append the @done tag, which does as expected. But because there might be “native” tags coming in the future, I want to make sure the script doesn’t cause filtering problems down the road. Because ChatGPT built it after a few trials and errors, it might also be needlessly complex.
Any suggestions/words of caution?
tell application "Bike"
tell front document
set selectedRow to selection row
-- Get the current content of the selected row
set currentContent to name of selectedRow
-- Check for the presence of a data-done attribute
set hasDoneAttribute to false
set doneAttributeValue to ""
repeat with attr in attributes of selectedRow
if name of attr is "data-done" then
set hasDoneAttribute to true
set doneAttributeValue to value of attr
exit repeat
end if
end repeat
if hasDoneAttribute then
-- If a data-done attribute is present, remove it
delete attribute "data-done" of selectedRow
-- Only attempt to remove the @done tag if the attribute's value is long enough to contain a date
if (length of doneAttributeValue) ≥ 10 then
set tagToRemove to " @done(" & text 1 thru 10 of doneAttributeValue & ")"
if currentContent contains tagToRemove then
set name of selectedRow to text 1 thru -((length of tagToRemove) + 1) of currentContent
end if
end if
else
-- Get the current date in the desired format
set currentDate to do shell script "date '+%Y-%m-%d'"
set currentTimestamp to do shell script "date -u '+%Y-%m-%dT%H:%M:%SZ'"
-- Add the "data-done" attribute with the current timestamp value
make new attribute with properties {name:"data-done", value:currentTimestamp} at selectedRow
-- Append the "@done(YYYY-MM-DD)" tag to the content
set doneTag to " @done(" & currentDate & ")"
set name of selectedRow to currentContent & doneTag
end if
end tell
end tell