I have a smart rule which detects on import HTML documents from a specific website we shall call JW. The smart rule converts the HTML to PDF (one page). What I would like to do is move the HTML file to trash and the newly created PDF to a group. But I can’t figure out how.
if I use Convert then the following actions apply to the original HTML, ie I can then use Move to Trash. But I can’t use the smart rule to then move the newly created PDF
if I use Convert and Continue, I can move the PDF to a group, but not the HTML to trash
if I use Convert, and then set up a second rule to move any PDF created from website JW, then the smart rule doesn’t trigger, because apparently the Convert action neither counts as “on import” nor “on creation”.
Any ideas? Is set theCopy to create PDF document from theRecord without pagination identical to the smart rule action “Convert to PDF (single page)” (i.e. runs exactly the same technical routine?) Then presumably I could script this, moving theRecord to trash and theCopy to where the group I want? Looking at Criss’ script which downloads and then converts to PDF, he uses parents of theRecord, and I’m not sure I understand why. (I specifically do not want to download and convert, however - the website only works when I clip it as html; so I wouldn’t need the “parents” bit, but could use theRecord, couldn’t I?).
Thanks for any hints & input If you can point me in the right direction, I’ll play with scripting
EDIT: create PDF document from is only used for a URL, so that’s not the solution. Any other ideas? Can I run a script within the smart rule AFTER the smart rule has converted the HTML to PDF and identify both records in the script? If so, how? theRecord and yourknowtheotherRecord sort of thing
I assume that the records have the same name (bar the extension) after conversion. In the script, you could move the original one to the trash and then search for the remaining one with the same name but type of PDF. Move that to the appropriate group.
That’s an idea, thanks. It’d probably be easier to move the html file to trash using the script, as I want to do a couple of other things with the pdf; I’m thinking of something along the lines of
set theSearchterm to the name of theRecord -- the PDF file as created by the smart rule
repeat with theFile in theFilesintheInbox
if the name of theFile is equal to theSearchterm then
if the record type is html then
move record theFile to the trash group of theDatabase
So a couple of questions (if anybody feels inclined to share their knowledge or even just point to a knowledge source) I haven’t been able to answer: how do I define the records in the inbox? (i.e. correctly write or define the repeat with theFile in theFilesintheInbox line). And how do I correctly delimit the property of the record, so that the action is only performed if the record type is html? Thanks all
You were talking about a smart rule at the beginning. So you could use its dialog box to
limit its scope to the Inbox(es)
limit it’s action to files of kind “HTML”
convert the files to pdf in the action part of the rule
use an internal or external script to do the rest, like so (UNTESTED!)
repeat with theRecord in theRecords
if the type of theRecord is html
move theRecord to the trash group of theRecord's database
Here, theRecords are the records matched by the criteria of the smart rule (scope & file kind).
This script assumes that theRecords contain the originally selected HTML files, not the ones converted to PDF. In this case you don’t need the name of the record(s) at all, since you want to get rid of them anyway. However, if you plan on working with the PDF files in the same rule, you have to
get at the HTML file’s name and use it to locate the PDF before you delete the HTML file itself.
It would be more convenient, I think, if you could call another smart rule to process the HTML files from inside the first one. But that’s not possible (yet?)
I was going to write that that won’t work - because it still brings with it the problem that “theRecords” is either the html file or the pdf file - and I need to work with both. But - um - I’ve just come up with the blindingly obvious solution, requiring no scripting or anything…
Tadaaaa: first move the html file to trash, then use Convert and Continue. That, of course, creates the PDF in trash, but the next action simply moves it out of trash.
Thanks @chrillek for your input - I honestly appreciate the effort you put in to helping me come along with scripting and using DT.
Even after performing “Convert and Continue”? That would mean that theRecord is always the subject of the smart rule, and isn’t influenced by the actions of the smart rule. That’s useful to know, because it does open up the possibility of doing something with both files if the need arises. Thanks