Copy email subject and paste into text string

Hi - I would like to create a macro that copies the text from an email subject line and pastes it into a text string. Not sure how to get the subject or set up the text.
I’m using MS Outlook 2016 for Mac.

Like this:

Subject: Invoice 94215 for October 2015 (this is something I would type into the subject of a new email)

“Please find attached [subject line text]. Please confirm receipt by reply email and let us know if you have any questions”

Hey Scott,

You don’t say what email client you’re using.

You’re saying you want to get the subject from the current email and add it to the correct places in different strings?

For pasting?

-Chris

I’m using Outlook 2016

Yes, subject from current email and add to string.

Thanks!! SP.

Hey Scott,

Here's the basics.

-Chris

[Edited 2016/02/13 02:26 CST to correct a minor issue in the AppleScript – also added error-checking to the script.]


Microsoft Outlook » Extract Email Subject and Replace in Template.kmmacros (4.9 KB)

Wow, thanks Chris! I’ll try this tonight and let you know. Awesome!!! SP

Changes to the macro in post #4.

  • Replaced the evil result variable in the AppleScript with the proper one. (Thanks JM.)
  • Added error-checking to the AppleScript

-ccs

HI Chris - this might be basic, but I can’t see the end of the applescript text due to the scroll bar after the ddButton line. is it just “end try”?? thanks

Hey Scott,

That's why the macro is downloadable.  :smiley:

-Chris

Ha! I I didn’t see that. Sorry.

Thanks again!

Hey Chris, so when the script runs, this text box pops up. Thoughts on where to fix?

Hey Scott,

That's because the last action is Display Text (in a window).

I put that in to give a visual demonstration of the find/replace.

You can remove or disable that action.

-Chris

Right, I got that. But you see the subject is missing from the text - it wasn’t picked up. In this example, the subject is “Invoice 330040 March 2016”, so would expect the text string to be:

“Please find attached Invoice 330040 March 2016. Please confirm receipt by reply email and let us know if you have any questions.”

…also, would it be simpler to just set the subject variable and then insert text by pasting action with the variable?

thanks!

Hey Scott,

Oh, I see what you mean.

Are you operating on an outgoing email?

If so that's a different kettle of fish and will require changing the AppleScript.

Give me a step-by-step outline of what you're doing.

-Chris

Ah, sorry about that….

  1. open a new message, and i’ll type the subject e.g. “Invoice 33005 March 2016”
  2. place cursor in email body, type hotkey to paste text:

“Please find attached Invoice 33005 March 2016. Please confirm receipt by email and let us know if you have any questions.”

…like that.

Hey Scott,

Run this from the Script Editor.app and see if it works.

It sort of works in Outlook 2011 but has a glitch.

------------------------------------------------------------
# AppleScript
# Set body of front draft message to its subject.
------------------------------------------------------------
tell application "Microsoft Outlook"
  tell front draft window
    save
    tell its object
      set its content to (get its subject)
      set msgID to its id
    end tell
    save
  end tell
end tell
------------------------------------------------------------

If it doesn’t work run this script from the Script Editor.app.

------------------------------------------------------------
# AppleScript
# Set body of front draft message to its subject.
------------------------------------------------------------
tell application "Microsoft Outlook"
  tell front draft window
    save
    tell its object
      set its content to (get its subject)
      set msgID to its id
    end tell
    save
    delay 0.1
    close
  end tell
  open outgoing message id msgID of drafts
end tell
------------------------------------------------------------

We’ll see if either one work with Outlook 2016 and then decide what to do.

-Chris

Thanks Chris, I’ll give these a try later today. Was also thinking maybe a way to make this much more simple is to just copy the subject to the clipboard manually then have a script to paste the text with the clipboard text.

  • manually type subject, highlight and copy to clipboard

  • manually put cursor in message body, press hotkey to paste text with subject (from the clipboard) in the correct place.

Easier?

Run the scripts – especially the first one.

If that doesn't work we'll think about “easier”.  :sunglasses:

-Chris

The first doesn’t seem to do anything. The second seems to move the message window.
http://somup.com/cDnocxTz8

Hey Scott,

Vid 1 would not load at all (no matter). Vid 2 worked fine.

You didn't tell me you had a signature in the message. (All that stuff is relevant.)

Okay. It seems Microsoft has not bothered to fix this years old problem in Outlook's AppleScript dictionary, and that seriously sucks.

Moving on. We'll use the brute-force method.

Type your subject. Run the macro.

-Chris


Microsoft Outlook » Extract Email Subject and Replace in Template v2.kmmacros (3.8 KB)

Well okay! That works perfectly, thanks Chris, another example of the awesomeness of KBM AND the forum. Thanks again, really do appreciate the help. This will be the basis of several tedious repeating tasks!