Hi
I will try to describe what I want to accomplish :
Basically I have a computer set up with an email account running Apple Mail.app, and a excel .xls file (can also be converted into a numbers file if that is easier with OS X/Applescript) containing 4 columns and a vast number of rows. The columns are “Client name”, “client id 1”, “client code”, “email-address”.
To this e-mail account there are invoices sent (pdf’s) that I need forward/send out to my clients using my XLS sheet containing the email-addresses.
Today I have:
An applescript that saves the attached files/pdfs to a specific folder. An Automator folder-action tied to another specific folder on my mac, that when I drop a single pdf/invoice into that folder, Automator opens a new email with a specific signature and attaches the invoice/pdf, allowing me to type in the email address for the specific client. I search my XLS sheet manually for the client id of the pdf invoice and look for the email address in the next collumn (same row) and copy/paste that emailaddress manually. This is time consuming.
I would like (if possible) automate this whole process :
Save attached pdf to a folder (I HAVE SOLVED THIS USING THE FOLLOWING SCRIPT):
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
set attachmentsFolder to "Volumes:Macintosh HD:folderxxx:" as rich text
tell application "Mail"
set selectedMessages to theMessages
try
repeat with theMessage in selectedMessages
repeat with theAttachment in theMessage's mail attachments
set originalName to name of theAttachment
set savePath to attachmentsFolder & originalName
save theAttachment in file (savePath)
end repeat
end repeat
end try
end tell
end perform mail action with messages
end using terms from
- This is going to be the tricky part I guess:
Using the same folder as a hot folder/connected action, and:
- open the pdf in Preview
- search text within the PDF in Preview app for the number right next to “Kundnr” (swedish for “client id”) in the pdf.
- copy that number (client id) to clipboard
UPDATE: I have solved this one like this:
tell application "Adobe Acrobat Pro"
activate
tell active doc
repeat with i from 1 to count of pages
tell page i
set {L, T, R, B} to media box
set crop box to {L + 146, T - 200, R - 389, B + 655}
end tell
end repeat
end tell
end tell
activate application "Adobe Acrobat Pro"
tell application "System Events"
tell process "Acrobat"
keystroke "a" using {command down}
keystroke "c" using {command down}
end tell
end tell
tell application "Adobe Acrobat Pro"
activate
close all docs saving "No"
end tell
- Search the XLS sheet for the client id from clipboard
- Select the column right next to (to the right in the XLS sheet) which will contain e-mailaddress (in the same row)
- Copy email address to clipboard
UPDATE:
Continuing the AppleScript above with this code, Im able to get this half working as well:
set client_id to "somestuff"
get (the clipboard) = client_id
tell application "Microsoft Excel"
set file_path to "Volumes:Main HD:path:to:file:export.xlsx"
open file_path
try
set searchRange to range ("A2:B11000")
set foundRange to find searchRange what "5700" look at whole with match case
set fRow to first row index of foundRange
set client_email to value of range ("C" & fRow as text)
end try
end tell
However Im not able to search Excel for my variable that was set previosly, in this line:
set foundRange to find searchRange what "5700" look at whole with match case
I would like to write client_id instead of “5700”. But that doesnt work in my script,
Question Does anyone know what Im doing wrong there?
Is this the right way of defining the variable client_id and paste the contents from the clipboard to client_id ?
set client_id to "somestuff"
get (the clipboard) = client_id
- Open a new email in Mail.app using a specific email account and a specific email signature (I HAVE AN AUTOMATOR ACTION FOR THIS PART, that I cant seem to find right now though)
- Paste the email address to the client (copied in the section 3 above), stored in the variable “client_email”
- Send the email
However. Some of my clients doesn’t accept their invoices to be emailed to them. For these clients I have chosen to add the word “post” instead of an e-mail address in the XLS sheet. It would be nice if these invoices are not emailed when the search in section 3 equals “post”. The best would rather be if they were sent/printed to the default installed printer instead. Or tagged with a color coding in OS X / Finder (for me to manually print later on).
I don’t know the forum rules 100%, but I would be happy to PayPal someone that could help me with this, if it can be accomplished.
Thanks for taking the time to read
/Niklas