AppleScript to attach photo to end of open Mail message - email

In Dec. 2012, Mark Hunte of this stackoverflow site helped another user by providing the following AppleScript. The script creates a new email msg. and attaches a file to the end.
Could anyone here please help me? I need to have a shortened version of this script that only does one thing: attach a file named "selectedPhoto.jpg" to the end of an already open email.
That is, if I am creating a new email or replying to an email and already have the window open, I would like to run a script that simply attaches a photo to the end of that email.
I have tried taking out lines of the following script, but I can't get it to work.
I am running OS X 10.8
Can someone help?
set theAttachment1 to POSIX file "/Users/USERNAME/Desktop/Desktop--IMAGE/scooter-6.jpg"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:"subject", content:"the_content" & return & return}
tell newMessage
set visible to false
set sender to "myaddress#btinternet.com"
make new to recipient at end of to recipients with properties {address:"someAddress#btinternet.com"}
make new attachment with properties {file name:theAttachment1} at after the last paragraph
(* change save to send to send*)
save --<<<<---------------- change save to send to send
(* change save to send to send*)
end tell
end tell

I couldn't get tell outgoing message 1 to make new attachment to work, but you could use UI scripting:
set old to the clipboard as record
set f to "/Library/Desktop Pictures/Antelope Canyon.jpg"
set the clipboard to (read (POSIX file f as alias) as JPEG picture)
activate application "Mail"
tell application "System Events" to keystroke "v" using command down
set the clipboard to old

Related

Automatically download emails from Outlook with SAS or Outlook rule

I am trying to create a program to automatically download the attached files that are sent to us from a certain email and then transform the delimiter with SAS, of those csv that are attached to us and pass those csv through a flow that I have already created.
I have managed to create a program that treats the csv as I want and the delimiter that I want, the problem is that when it comes to automating the download of files from Outlook it does not work.
What I have done is create a rule with the following VB code that I found on the internet:
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "C:\Users\ES010246\Desktop"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
I have changed the path to my personal path where i want the files are downloaded.
website: https://es.extendoffice.com/documents/outlook/3747-outlook
The problem is that this code does not work for me, it does absolutely nothing for me and no matter how much I search the internet, only this code appears.
Is there any other way to do with SAS what I want? What is it to automatically download 8 csv files sent to me by Outlook, or has someone experienced the same thing as me with VBA?
I have followed all the steps about 7 times so I think the error is not in copying the code or selecting certain options wrong, in fact I had copied and pasted the code and later I modified the path where I wanted those to be saved. files but it doesn't work, does anyone know why?
I will be tremendously grateful, thank you very much for everything!
First of all, you need to make sure the file name and path doesn't include forbidden symbols.
The VBA macro used for a rule in Outlook is absolutely valid except that a mail item may contain the attached files with the same name, so a file saved to the disk may be overwritten (saved with the same name). That's why I'd suggest generating a file name with your own unique IDs making sure that DisplayName property is not empty and has a valid name what can be used for file names (exclude forbidden symbols).
Also you may consider handling the NewMailEx event of the Application class which is fired when a new message arrives in the Inbox and before client rule processing occurs. Use the Entry ID returned in the EntryIDCollection string to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem.
The Items.ItemAdd event can be helpful when items are moved to a folder (from Inbox). This event does not run when a large number of items are added to the folder at once.

receive windows popup message or alert for a specific incoming mail

we have following problem. we need an extra windows popup message or baloon tip message in windows, if a mail from a specific sender arrives in outlook. are there any examples in powershell or any other programms recommend?
thanks in advance
You can use basic Outlook rules to create a desktop alert with any given condition, no need for any script or special program
If you want, the rule can also run a script and then you can do whatever you want there
From the following webpage, https://www.slipstick.com/outlook/rules/outlooks-rules-and-alerts-run-a-script/
Using VBA
Something like this:
Public Sub ShowMessage(Item As Outlook.MailItem)
'code
End Sub
The argument must by type MailItem or MeetingItem for the subroutine to be available in the Rules Wizard in Outlook 2007. In Outlook 2010 and 2013 (and up), PostItem also works.
Open Rules Wizard. In Outlook 2010 and 2013, it's on Outlook's Home ribbon,
Rules > Manage Rules & Alerts. Look on the Tools menu in older versions.
Open Rules Wizard
Click New Rule.
Select Apply Rule on messages I receive and click Next.
Select your conditions and click Next.
Select Run a script action (near the bottom).
The finished run a script rule
Click on a script.
Select the script
Select your script, click OK.
Click Next then finish the rule.
There are several ways to get the job done:
Create a rule in Outlook manually and assign a VBA macro which can be triggered by the rule. For example:
Public Sub TestRule(Item As Object)
If(Item.SenderEmailAddress = "eugene#test.com") Then
MsgBox "Got email!"
End If
End Sub
Use the VBA routine for handling incoming emails. The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item.
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim mai as Object
Set mai = Application.Session.GetItemFromID(EntryIDCollection)
If(mai.SenderEmailAddress = "eugene#test.com") Then
MsgBox "Got email!"
End If
End Sub

write a code to fill a form on the web and read one of the elements

I am periodically checking a website which requires me to fill a form. When I fill the form, a window pops up which includes the information I am looking for.
I was wondering if there is a way to write a program to fill the form and extract the fields that are of importance to me.
If possible,
What language is easier for doing so?
Is there any way to read one of the elements on the window that pops up? (When you right-clik on an item and select inspect element)
Could you please provide links and tutorials to implement this, so that I could write the program ASAP?
Update:
The solution using VBScript is posted. I would appreciate it if you post other solutions that could be used under OSX or Linux (Preferably OSX)
Yes we can.. one way to do it using VBS is here:
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = 1
objIE.navigate "<login url>"
WScript.Echo "Opening login page..."
WScript.Sleep 100
Do while objIE.busy
Wscript.sleep 200
Loop
WScript.Echo "Setting credentials..."
objIE.Document.getElementByID("ap_email").Value = user 'id of the input element
objIE.Document.getElementByID("ap_password").Value = pass
WScript.Echo "Email and password set!"
Call objIE.Document.Forms(0).submit
HTH!

AppleScript - Expected end of line but found identifier when opening email program

I'm working on building a small plugin in AppleScript that will find the default mail app and open that up and paste in a subject and body.
I get the error "Expected end of line but found identifier."
on run
set mailClient to getDefaultMailClient() -- store application id
tell application id mailClient
set msg to make new outgoing message with properties {subject:"subject here", visible:true}
tell msg to make new to recipient with properties {address:"email.com"}
end tell
end run
on getDefaultMailClient()
set prefPath to (path to preferences as text) & "com.apple.LaunchServices.plist"
tell application "System Events"
try
value of property list item "LSHandlerRoleAll" of ¬
(first property list item of property list item "LSHandlers" of ¬
property list file prefPath whose value of property list items ¬
contains "mailto")
on error
"com.apple.mail"
end try
end tell
end getDefaultMailClient
This works fine when it opens up the program Mail on my computer but I want it to work for Entourage and any other email program for OSX.
Any help is much appreciated.
Rather than anticipate various clients and create specific code for them, you can take advantage of the abstraction the mailto: URL scheme provides - it will open a new email form in the default email client:
on newEmailForm(addr, subj, body)
do shell script "open " & ¬
quoted form of ("mailto:" & addr & "?subject=" & subj & "&body=" & body)
end newEmailForm
# Sample invocation:
my newEmailForm("somebody#some.net", "This is my subject line", "")
Note that the above uses do shell script with open rather than open location - the former conveniently automatically encodes the strings for inclusion in a URI, whereas the latter requires you to pass an already-encoded string.
You can do this by writing commands for each client.
if mailClient = "com.apple.mail" then
tell application "Mail"
--insert your code
end tell
else if mailClient = "com.something.else" then
tell application "something.else"
--insert your code
end tell
end if

How do I get the default mail client using applescript?

Can anyone please tell me, how do I get the default mail client using applescript?
I found part of this code here, ran it on Snow Leopard (10.6.4), and it worked for me.
on run
set mailClient to getDefaultMailClient() -- store application id
tell application id mailClient to activate -- tell mail client to do something
end run
-- Grab id of default mail client
on getDefaultMailClient()
set prefPath to (path to preferences as text) & "com.apple.LaunchServices.plist"
tell application "System Events"
try
value of property list item "LSHandlerRoleAll" of ¬
(first property list item of property list item "LSHandlers" of ¬
property list file prefPath whose value of property list items ¬
contains "mailto")
on error
"com.apple.mail"
end try
end tell
end getDefaultMailClient
Another option: VERSIONER_PERL_PREFER_32_BIT=1 perl -MMac::InternetConfig -le 'print +(GetICHelper "mailto")[1]'
there has been a discussion on this toppic in the macscripter-forum
there you find also some code examples on how test for the default mail-client