I am using a script to clip selected text from PDF to a new html document. I am creating a HTML record because it allows me to append the page link url more easily than if the file was RTF.
After creating the clipping I often add a spotlight comment to remind myself why it is important.
Can someone help me with a script to append spotlight comments to their respective html documents. I would be very happy if this worked on multiple file selections (batch) at the same time. I drag these clippings into Scrivener and it would be handy to have the comment too.
Thanks for the help DEVONthink community.
Can you provide more information about this? You said you’re adding Spotlight comments but under what criteria would a document be “respective”?
Are you wanting to select some files and add the same comment to them all?
Sorry that this wasn’t clear. Each clipping (HTML file) has its own comment. I want to append that comment to the document so when I drag it out of DT the information stays together.
Hopefully this is more clear.
Thanks for the help!
So you want the comment to be inserted into the content of the HTML file, correct?
Yes, that’s right. Hopefully not too difficult!
Due to the differences in HTML files, there is no way to gauge if this will always work. Also, it would use basic styling, ie. it may not look pretty, depending on the styling of the page. But here is one approach…
-- Insert Spotlight Comment at end of HTML file
-- Created by Jim Neumann / BLUEFROG on Sun Jul 29 2018.
-- Copyright (c) 2018 BLUEFROG / DEVONtechnologies, LLC. All rights reserved.
tell application id "DNtp"
repeat with thisRecord in (selection as list)
if (type of thisRecord) = html then
do shell script "sed -i '' '/<\\/body>/ i\\
<p>" & comment & "</p>
' " & (quoted form of (path as string))
Thanks for sharing the script BLUEFROG. Unfortunately, it is failing on my machine… meaning it doesn’t seem to do anything when I execute the script.
Do you have an HTML with a comment selected when you run it?
When I run the script… the DT editing pane flickers for a split second (so something must be happening)… but no changes.
I’m not sure what you’re referring to here.
Sorry if my terminology is incorrect… I was referring to the pane where you can view/edit the file…in three pane mode…
Have you looked at the very bottom of the page you ran the script on?
Yes. I also checked the source of the html file after running the script.
How is it working on your end?
Do you have multi-line comments?
I add comments in DT in three pane mode (spotlight comment column). They are one line comments. I tried several files – even one with a one word comment. Nothing seems to work.
Thanks for taking the time to troubleshoot this - I appreciate the difficulty of this on a forum and that it requires additional development beyond the core product.
Are you running the script from Script Editor? If not, please do and tell me if it’s reporting an error.
PS: You’re welcome.
PS: Here is what I’m seeing…
I was running the script via the script menu in DT.
I just ran it in script editor with the file selected in DT – result in the script editor is “” <- literally two quotes. Empty string? Nothing was appended to the file.
Interesting… Would you open a support ticket so we can dig a little deeper? Thanks!