Hi,
My goal is to augment the merge function by having it add the names of the component documents in right-justified text before the respective content. I have tried to do this with Christian Grunenberg’s merge.scpt which is available from here devon-technologies.com/files … cripts.zip
However there remain two problems that I have not been able to solve.
-
merge.scpt does not handle images like the built-in merge function does - it seems to only handle text. I can’t figure out how to manipulate a png, or a pdf, or to ‘extract’ and ‘insert’ the image portion of an rtfd.
-
I can’t figure out how to format each document name so that it is right-justified to distinguish it from original content.
Thanks, any scripting help would be greatly appreciated.
Rich text scripting is limited/tricky, see viewtopic.php?f=20&t=11221#p52653
Thank you Christian for the link. The solution I have come up with is to cast the merged document in html, so that formatting is described with explicit html commands instead of rt attributes. Here is a simple example:
tell application id "com.devon-technologies.thinkpro2"
--activate
try
set this_selection to the selection
if (count of this_selection) < 2 then error "Please select multiple items."
set this_name to "merge2HTML"
set this_result to "<html>" & return
set this_result to this_result & "<body>" & return
repeat with this_item in this_selection
-- build the new record contents
set this_result to this_result & "<div style=\"display: block; padding-left: 2em; padding-right: 2em; padding-bottom: 2em; background-color: #FFFFFF\">" & return
set this_result to this_result & (rich text of this_item) & return
set this_result to this_result & "</div>" & return
end repeat
set this_result to this_result & return & "</body>" & return & "</html>"
create record with {type:html, source:this_result, name:this_name} in current group
end if
end try
end tell
The convert record method is useful in these contexts.
rich --> html to create a more easily editable version,
and html --> rich if a rich text output is needed.
(A new record is created, and the old one can be deleted).
For cases where there are linked/embedded graphics, using the shell’s textutil for html–>rtfd conversion also works well, perhaps in combination with pbcopy/pbpaste. A new record can be created by importing the resulting rtfd file/package.