How Do I Copy 6 Fields of Text From an Email & Paste Into My Notes App?

Concatenating is absolutely happening. I’m on my phone so can’t show visuals at the moment… but the way I have it set is:

Set %filename% to %v1%v2%v3%

Then way down the line I have

Save as %filename%
Email- attach %filename%

Obviously just a quick representation of what it is... If you need visuals then they are in the thread. Or I can show tomorrow or later.

Yes so the point of tue macro is.. if entity is X and Client is Y, pull this time sheet (local drive). In the top 3 fields, enter name - employee ID, classification.

Save as using the naming variable (string) to a different folder (for backup and tracking purposes)
Email that file

It needs to be save as (or similar) because the original file needs to be clean for the next worker that ends up pulling that timesheet.

My company has 2 entities. Within those entities, like 30 clients. I used your help in the beginning of when it was parsing an email for variables. Two of those variables dictate the document that gets pulled. The other variables for filling in the doc with that workers info.

What app are you saving your file from in the first place???

Excel.

Excel is scriptable. You can do something like this:

l --------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2022/11/08 20:00
# dMod: 2022/11/11 00:03
# Appl: Microsoft Excel
# Task: Create New Workbook and Save With a Specific Name In a Specific Folder.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Microsoft_Excel
# Vers: 1.01
--------------------------------------------------------
use AppleScript version "2.4" --» Yosemite or later
use framework "Foundation"
use scripting additions
--------------------------------------------------------

# Path to Excel template file:
set templateFile to "~/Desktop/test.xlsx"
set templateFile to ((current application's NSString's stringWithString:templateFile)'s stringByExpandingTildeInPath) as text

# Create new path for temporarily saved version of modified template file (to be emailed).
set saveDir to path to desktop folder as text
set newExcelFilePath to saveDir & "New Workbook Name.xlsx"

tell application "Microsoft Excel"
   activate
   
   # Open the template.
   open templateFile
   # Save a temporary working version to a new location.
   # (You may have to authorize Excel to use this location.)
   save active workbook in newExcelFilePath
   
   tell active sheet
      set value of cell "A1" to "Philip"
      set value of cell "B1" to "Marlowe"
      set value of cell "C1" to "Private Eye"
   end tell
   
   save active workbook
   close front window
   
end tell

--------------------------------------------------------

You must love this stuff. Looks intense, I will get at it first thing in the morning. Thank you.

@ccstone,

As I extremely impressed and grateful for this Excel script, it confuses me.

Still trying to get comfortable with AppleScript and KM itself.

Does the script run on every spreadsheet in the macro?

Nyet...

I will add some comments to the script above to make it a bit more newbie friendly.

The script:

  • Opens the template at the given path: ~/Desktop/test.xlsx
  • Saves it as a new working file to a new location and file name.
  • Changes the value of three specific cells (as an example of what you can do).
  • Saves the workbook.
  • Closes the workbook in readiness for emailing.

The script could also perform the entire email process (KM email action uses AppleScript behind the scenes).

1 Like

Howdy. Revisiting this thread because I have an issue that uses what we spoke about here.

I am using regex (supplied by @Nige_S) to pull a string from a variable.
The problem is on my companies end, not KM. But if it is solvable on my end (KM), awesome.

Background - We have Job titles (class) that the client has entered an extra space after the title. When trying to enter this info into a data validated cell in Excel, it won't allow because of that extra space after the classification. The string pulled by regex (saved to local_Class) doesn't contain that extra space because the user doesn't see it when applying the information for the regex to grab.

My hope - Is there a way to do input into excel, give or take a space, when there is a data validation drop down with preset entries?

image

The best way to sort this is at data entry -- those titles should be validated when the client enters them originally, for example by only allowing them to choose titles from a preset list or by trimming leading/trailing spaces on submission.

But I'm guessing you have little control of that stage :frowning: I'm also guessing that if they put in trailing spaces, they might also fat-finger leading spaces...

So if you want to "extract the text from local_NHF, minus any leading or trailing spaces" you have (at least) two approaches:

  1. Use the "Search" you already have, but then apply a "Filter" action to local_Class -- one of the filters is "Trim Whitespace", which will do just what you want.

  2. Change your Regular Expression so it matches the potential extra spaces but doesn't capture them. The front spaces are easy -- \s* for "zero or more whitespace characters, but you can't do just that for the trailing because even it it finds a space the preceding (.*) is greedy and will have matched it first. Changing that to match "everything but a space" might help, but will break if you have two-word titles.
    Instead we can change it to a non-greedy (or lazy) match -- (.*?) -- which lets the final \s* gobble up as many spaces as it can, leaving none for our capture group. So

(?m)^Class:\s*(.*?)\s*$

...will capture the job title, without any reading or trailing spaces if they are present, and the result should validate in your spreadsheet.

Try both, with and without the ? and with and without the extra spaces, in https://regex101.com to see how this works.

1 Like

As always, the best. Thank you for your help, @Nige_S It worked great.