I have used this script from @pete31 to have a group that shows every doc I hit on a given day. I don’t look at the results daily, but if I need to remind myself of something, it is helpful. The Smart Rule gives me the following error:
On performSmartRule (Expected end of line, etc. but found number.)
I have looked at the code and with my extremely limited AppleScript knowledge, cannot figure out what it means. Any insight is appreciated. Thanks. Code for script is below:
property sortByLastOpened : true
property theExcludedDatabaseNames : {"_temp"}
on performSmartRule(theRecords)
tell application id "DNtp"
try
repeat with thisRecord in theRecords
if (name of database of thisRecord) is not in theExcludedDatabaseNames then
set theHistoryRecord_Name to my formatDate(current date) & space & "Activity Record"
set theResults to search "kind:markdown {any: name==" & theHistoryRecord_Name & " name==" & theHistoryRecord_Name & ".md}"
if theResults ≠ {} then
set theHistoryRecord to item 1 of theResults
set theHistoryRecord_Text to plain text of theHistoryRecord
else
set theGroup to create location "/Daily Activity Record" in database named "FLI"
set theHistoryRecord_Text to "<style> a {text-decoration: none;} </style>" & linefeed & linefeed & "# " & theHistoryRecord_Name & linefeed
set theHistoryRecord to create record with {name:theHistoryRecord_Name, type:markdown, plain text:theHistoryRecord_Text, exclude from see also:true, unread:false} in theGroup
end if
set thisRecord_ReferenceURL to reference URL of thisRecord
if thisRecord_ReferenceURL ≠ (reference URL of theHistoryRecord) then
--added to original script:
set {year:y, month:m, day:d, time:t} to (current date)
set theTime to my secsToHMS(t as integer)
set theDatabase to the name of current database
--end addition
set thisMarkdownLink to (theTime & ": " & "**" & theDatabase & "** : " & "[" & my escapeLinkName(name of thisRecord) & "](" & thisRecord_ReferenceURL & ")") as string
if theHistoryRecord_Text does not contain thisRecord_ReferenceURL then
set plain text of theHistoryRecord to theHistoryRecord_Text & linefeed & "* " & thisMarkdownLink & space & space
else if sortByLastOpened then
set plain text of theHistoryRecord to my updateOrder(theHistoryRecord_Text, thisRecord_ReferenceURL, thisMarkdownLink)
end if
end if
end if
end repeat
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
return
end try
end tell
end performSmartRule
on formatDate(theDate)
set theYear to year of theDate as string
set theMonth to ((month of theDate) as integer) as string
if (count theMonth) < 2 then set theMonth to "0" & theMonth
set theDay to day of theDate as string
if (count theDay) < 2 then set theDay to "0" & theDay
return theYear & "-" & theMonth & "-" & theDay
end formatDate
on escapeLinkName(theText)
set d to AppleScript's text item delimiters
repeat with thisCharacter in {"[", "]", "(", ")", ">"}
set AppleScript's text item delimiters to {"\\" & thisCharacter, thisCharacter}
set theTextItems to text items of theText
set AppleScript's text item delimiters to "\\" & thisCharacter
set theText to theTextItems as text
end repeat
set AppleScript's text item delimiters to d
return theText
end escapeLinkName
--added to original script: this gets the current time
on secsToHMS(secs)
--from <http://macscripter.net/viewtopic.php?id=27203>
tell (1000000 + secs div hours * 10000 + secs mod hours div minutes * 100 + secs mod minutes) as string ¬
to return texts 2 thru 3 & ":" & texts 4 thru 5 & ":" & texts 6 thru 7
end secsToHMS
on updateOrder(theText, theReferenceURL, theMarkdownLink)
set theDelimiters to {"(" & theReferenceURL & ")" & space & space & linefeed, "(" & theReferenceURL & ")" & space & space}
set theTextItems to my tid(theText, theDelimiters)
set theTextItems_modified to {}
repeat with i from 1 to (count of theTextItems)
set thisTextItem to item i of theTextItems
set thisTextItem_Paragraphs to paragraphs of thisTextItem
set thisTextItem_Paragraphs_Count to (count of thisTextItem_Paragraphs)
if thisTextItem_Paragraphs_Count > 0 then
if item -1 in thisTextItem_Paragraphs contains "x-devonthink" then
set theTextItems_modified to theTextItems_modified & thisTextItem_Paragraphs
else if thisTextItem_Paragraphs_Count > 1 then
set theTextItems_modified to theTextItems_modified & items 1 thru -2 in thisTextItem_Paragraphs
end if
end if
end repeat
return my tid(theTextItems_modified, linefeed) & linefeed & "* " & theMarkdownLink & space & space
end updateOrder
on tid(theInput, theDelimiter)
set d to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
if class of theInput = text then
set theOutput to text items of theInput
else if class of theInput = list then
set theOutput to theInput as text
end if
set AppleScript's text item delimiters to d
return theOutput
end tid
type or paste code here