Hi, I am trying to copy one image and several blocks of text from a webpage using Applescript. It is working (in a fashion) but I have not found a method of doing the Image and the Text at the same time. My long winded method is as follows:
I save a copy of the image to a temp file on the desktop (FOO).
Find the correct text and place into variables.
Set the clipboard to the saved image (from my desktop).
Create a temp text file - paste the clipboard image to it.
set the clipboard to the text variables - paste them to the text file.
Copy the entire text file (image and text) - manually paste to where it needs to be.
The end result should be an image with several blocks of text underneath on the clipboard.
Can someone help make this slicker please? Can the image be stored as a variable too??
I can’t show the actual website here (I have to sign in), so I have just picked a website at random for the cut down example below.
-- Example website picked at random for example
-- https://cccbr.org.uk/bellringing/what-is-bell-ringing/
-- Image URL
set FullURL to "https://cccbr.org.uk/wp-content/uploads/2018/04/bampton.jpg"
tell application "Safari"
-- Save Image file from report to desktop as (FOO.JPG)
set newname to POSIX path of ((path to desktop) as text) & "foo.jpg"
set status to (do shell script "curl -s -o " & newname & space & FullURL's quoted form)
-- Gets all of the report and copies to variable
set theSource to source of the document 1
end tell
-- Converts the Report (Source) to a text variable
set FullRecord to do shell script "/bin/echo " & quoted form of theSource & " | /usr/bin/textutil -stdin -stdout -format html -inputencoding iso-8859-1 -convert txt -encoding UTF-8"
--Find the start and end of the comments
set FirstPgCommentsStart to offset of "The origins" in FullRecord
set FirstPgCommentsEnd to offset of "a method" in FullRecord
-- Comments into variable
set myComments to text (FirstPgCommentsStart) thru (FirstPgCommentsEnd + 8) of FullRecord
-- ** Need a better method from here **
-- Put the Image on the clipboard
try
set the clipboard to (read alias "Macintosh HD:Users:Me:Desktop:foo.jpg" as TIFF picture)
end try
-- Create TextEdit document as temp storage for both Image and Text
tell application "TextEdit"
activate
set newDoc to make new document
end tell
tell application "System Events" to keystroke "v" using command down
delay 1
set the clipboard to myComments
tell application "System Events" to keystroke "v" using command down
delay 0.5
tell application "System Events" to keystroke "a" using command down
delay 0.5
tell application "System Events" to keystroke "c" using command down
tell application "Safari"
activate
display dialog "Image and Text have been added to the Clipboard."
end tell