Wednesday, July 15, 2020
  • Index
  •  » Automator
  •  » Mix of Automator and AppleScript to send a specific e-mail template

#1 2020-02-14 08:19:06 am

Drotciv
Member
Registered: 2020-01-29
Posts: 1

Mix of Automator and AppleScript to send a specific e-mail template

Hello everyone,

I used the search bar and scrapped some bits of AppleScript here and there, but I cannot get my head around what I'd like to do.

So the basic objective would be to:

1. Copy a specific bit of information to the clipboard
2. Click on my app
3. It would create a new e-mail with a specific template
4. The content of the clipboard would paste on a specific line between already existing (template) text.

I think I am almost there, but do not know how to finish, or might have to redo it.

So here's what my Automator/AppleScript looks like so far:

1. Run AppleScript:

Applescript:

on run {input, parameters}
set targetFile to “/xxx/Clipboard.txt"
set lineNumberToErase to 1
do shell script "
sed -i '' -e '" & lineNumberToErase & "d' " & quoted form of targetFile
do shell script "
pbpaste > /xxx/Clipboard.txt"
set the_file to “/xxx/Firstpart.txt"

set the clipboard to (read the_file)
return input
end run

This erases the content of the target txt file and replaces it with the content of my clipboard.
It then targets another txt file where there is the first part of my e-mail template.

2. Get Contents of Clipboard

This allows the script to stick the piece of info I copied at the end of the first part of my template.

3. Set Value of Variable

Variable set to “Body” to paste this first part to the new e-mail’s body.

4. Run AppleScript

Applescript:

on run {input, parameters}
set the_file to “/xxx/Secondpart.txt"
set the clipboard to (read the_file)
return input
end run

This allows for the clipboard to copy the content of the second part of my template for the e-mail.

5. Get Contents of Clipboard
6. Set Value of Variable

5&6 = same as 2&3 but for the second part of the template

7. New Mail Message

Everything copies in the correct order to the new mail message.

It is super complicated and asks me to create 3 files that have to be in a specific location at all times.

I am doing this because I do not know how to insert the content of the clipboard in a specific spot within my text template, so dividing the template in half allows me to add a third step in the middle (copying the content of the clipboard between the two template parts)

The result is somewhat correct, but what I would like to know is how to make sure these txt files (if they are necessary) do not have to stay in a specific folder (maybe they could be inside the app? or something)
Also, would there be a way to paste the content of the clipboard in a specific spot on a specific line?
For example:
line 1 with text
line 2 with text
line 3 with text [clipboard content] text
line 4 with text etc.

Well anyways, thanks for reading!

Model: iMac Retina 5k 27in 2017
AppleScript: 2.11
Browser: Safari 605.1.15
Operating System: macOS 10.14

Last edited by Drotciv (2020-02-14 08:27:07 am)

Offline

 
  • Index
  •  » Automator
  •  » Mix of Automator and AppleScript to send a specific e-mail template

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)