I’m trying to set up an AppleScript that will get a path from a txt file(mockUPPath.txt) on the Desktop which in theory will allow me to attach a jpg. The name of the folder and jpg will change so I can’t hard code it. I also get the body of the email from another text file on the Desktop which I managed to get working. I can get it to build the email but not find and attach the jpg.
The text in the mockUPPath.txt file looks like this: Name_Mock-up/555.jpg.
The jpg 555.jpg is in a folder “Name_Mock-up” on the Desktop
This is what I have so far (below), anyone know where I’m going wrong?
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set AppleScript's text item delimiters to return
set theFile to ((path to desktop as text) & "mockUPText.txt")
set theData to paragraphs of (read file theFile)
set myPath to ((path to desktop as text) & "mockUPPath.txt")
set thePath to paragraphs of (read file myPath)
set newPath to (POSIX path of (path to desktop folder)) & thePath
--Email
set theMessageSubject to "Test email"
set theRecipient to "email@test.com"
set theMessageContent to theData
set theMessageAttachment to newPath
tell application "Mail"
activate
set theMessage to make new outgoing message with properties {visible:true, subject:theMessageSubject, content:theMessageContent & linefeed & linefeed}
tell theMessage
make new to recipient at end of to recipients with properties {address:theRecipient}
make new attachment with properties {file name:theMessageAttachment as alias} at after the last word of the last paragraph
end tell
end tell