Jump to content

This topic is 4819 days old. Please don't post here. Open a new topic instead.

Recommended Posts

There must be a way for fm pro to call an AppleScript that will open a new email in outlook 11 use the address from fm pro and then let me fill in the message body. I don't know any applescript

Link to comment
Share on other sites

The bad news is: You'll have to learn some AppleScript, and examples for Outlook 2011 seem to be sparse.

The good news is: From the little I can see (not having Outlook), the basic AppleScript commands are much the same as for Mail (or Entourage). In other words, an email app is an email app; their actions are much the same. Microsoft apps tend to have more AppleScript options than Apple apps, hence larger AppleScript dictionaries.*

Unfortunately there don't seem to be many posts at macscripter.net about Outlook 11. But I found this one, which shows how to set up and send an email from FileMaker:

http://macscripter.net/viewtopic.php?id=34833

*To see Outlook's AppleScript dictionary, open Apple's AppleScript Editor app. In the Window menu, choose Library. This will show you the dictionaries of applications. Click the + button to add Outlook. That will let you see all its commands and objects. Dictionary documentation is sparse on examples however. One of Apple's forums would likely have more examples if you get stuck. But the basic "create an email" AppleScript looks much the same as one for Mail.

Link to comment
Share on other sites

The bad news is: You'll have to learn some AppleScript, and examples for Outlook 2011 seem to be sparse.

The good news is: From the little I can see (not having Outlook), the basic AppleScript commands are much the same as for Mail (or Entourage). In other words, an email app is an email app; their actions are much the same. Microsoft apps tend to have more AppleScript options than Apple apps, hence larger AppleScript dictionaries.*

Unfortunately there don't seem to be many posts at macscripter.net about Outlook 11. But I found this one, which shows how to set up and send an email from FileMaker:

http://macscripter.net/viewtopic.php?id=34833

*To see Outlook's AppleScript dictionary, open Apple's AppleScript Editor app. In the Window menu, choose Library. This will show you the dictionaries of applications. Click the + button to add Outlook. That will let you see all its commands and objects. Dictionary documentation is sparse on examples however. One of Apple's forums would likely have more examples if you get stuck. But the basic "create an email" AppleScript looks much the same as one for Mail.

Thanks for the tip - I had been to that site but missed the post.

Link to comment
Share on other sites

Thanks for the tip - I had been to that site but missed the post.

so this is where I am up to in teaching myself Applescript...

set toAddr to "[email protected]"

set theSubject to "Testing Applescript"

set theContent to "This email is desgined to test the script"

tell application "Microsoft Outlook"

set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent}

the theMessage

make to recipient with properties {email address:toAddr}

end tell

It all works in as much as it creates an email in drafts with the correct subject and content...but I dont get the recipients email address and it tells me that it has an error:

error "Microsoft Outlook got an error: Can’t make \"[email protected]\" into type email address." number -1700 from "[email protected]" to email address

Help!?

Link to comment
Share on other sites

so this is where I am up to in teaching myself Applescript...

set toAddr to "[email protected]"

set theSubject to "Testing Applescript"

set theContent to "This email is desgined to test the script"

tell application "Microsoft Outlook"

set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent}

the theMessage

make to recipient with properties {email address:toAddr}

end tell

It all works in as much as it creates an email in drafts with the correct subject and content...but I dont get the recipients email address and it tells me that it has an error:

error "Microsoft Outlook got an error: Can’t make \"[email protected]\" into type email address." number -1700 from "[email protected]" to email address

Help!?

with some more tinkering I have got the message to open but it still will not accept the recipients address. The script is:

set Addr to "[email protected]"

set toName to "Robert Sheldon"

set theSubject to "Testing Applescript"

set theContent to "This email is desgined to test the script"

tell application "Microsoft Outlook"

set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, recipient:Addr}

open theMessage

end tell

The error message is:

error "Microsoft Outlook got an error: Can’t make \"[email protected]\" into type recipient." number -1700 from "[email protected]" to recipient

Link to comment
Share on other sites

Apparently the "to recipient" is more complex. In the example on that web page they have it as a separate line, a separate "tell theMessage" block, as in your first try. It may be possible to incorporate it into the one line. But, as you've seen, that is hard to do. I don't have Outlook, so I can't try it. From the example:

make new to recipient at tmp with properties {email address:{address:"[email protected]"}}

Whenever you see brackets {something} it generally means, "there's a possibiity of more than one of these." Sometimes they're optional if you have only 1 thing, sometimes not.

I believe someone once said, frustrated by these little glitches: "Applescript, the natural language programming language no one can use." While this is not really true, sometimes you need to fuss about to get it just right.

Link to comment
Share on other sites

Apparently the "to recipient" is more complex. In the example on that web page they have it as a separate line, a separate "tell theMessage" block, as in your first try. It may be possible to incorporate it into the one line. But, as you've seen, that is hard to do. I don't have Outlook, so I can't try it. From the example:

make new to recipient at tmp with properties {email address:{address:"[email protected]"}}

Whenever you see brackets {something} it generally means, "there's a possibiity of more than one of these." Sometimes they're optional if you have only 1 thing, sometimes not.

I believe someone once said, frustrated by these little glitches: "Applescript, the natural language programming language no one can use." While this is not really true, sometimes you need to fuss about to get it just right.

so I went back to the original and mimicked the example as follows:

make new to recipient with properties {email address:{address:toAddr}}

and I got an error message:

error "Microsoft Outlook got an error: Can’t make or move that element into that container." number -10024

I guess at least its a different error message!

so I went back to the original and mimicked the example as follows:

make new to recipient with properties {email address:{address:toAddr}}

and I got an error message:

error "Microsoft Outlook got an error: Can’t make or move that element into that container." number -10024

I guess at least its a different error message!

Yahoo...got it:

set toAddr to "[email protected]"

set theSubject to "Testing Applescript"

set theContent to "This email is desgined to test the script"

tell application "Microsoft Outlook"

set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent}

the theMessage

make new to recipient at theMessage with properties {email address:{address:toAddr}}

open theMessage

end tell

so I went back to the original and mimicked the example as follows:

make new to recipient with properties {email address:{address:toAddr}}

and I got an error message:

error "Microsoft Outlook got an error: Can’t make or move that element into that container." number -10024

I guess at least its a different error message!

Yahoo...got it:

set toAddr to "[email protected]"

set theSubject to "Testing Applescript"

set theContent to "This email is desgined to test the script"

tell application "Microsoft Outlook"

set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent}

the theMessage

make new to recipient at theMessage with properties {email address:{address:toAddr}}

open theMessage

end tell

Fenton - thanks for your help: this forum is unbelievable in the time that people give up in answering questions

so I went back to the original and mimicked the example as follows:

make new to recipient with properties {email address:{address:toAddr}}

and I got an error message:

error "Microsoft Outlook got an error: Can’t make or move that element into that container." number -10024

I guess at least its a different error message!

Yahoo...got it:

set toAddr to "[email protected]"

set theSubject to "Testing Applescript"

set theContent to "This email is desgined to test the script"

tell application "Microsoft Outlook"

set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent}

the theMessage

make new to recipient at theMessage with properties {email address:{address:toAddr}}

open theMessage

end tell

Fenton - thanks for your help: this forum is unbelievable in the time that people give up in answering questions

Now I have to workout hos fm pro passes data to Applescript

Link to comment
Share on other sites

One thing I've noticed in several of your code quotes. You have a line:

the theMessage

where it should be:

tell theMessage

That is likely why you had to add the "at theMessage" to your recipient line. Because "the theMessage" does nothing, so it did not know which message to add the recipient to. Either works. That is you can say:

tell object

  do something

end tell

or

do something at object

or

tell object to do something

AppleScript is flexible this way. Hence you can have two sets of code that do the same thing, but are written quite differently. It's just a different form of nesting.

To keep your life simple I recommend putting all the fields you're going to use in AppleScript on a dedicated layout. Then flip to that layout when the AppleScript is running. Then back (if desired). That way you can use the simplest form of syntax to target FileMaker fields; ie., no references to layout or table are needed within the AppleScript.

You pass data to AppleScript via FileMaker fields, including global fields. AppleScript cannot see script Variables.

set toAddr to cell "Email_address" of current record

That's it. "Email_address" is a FileMaker local field on the layout. It has been passed to the AppleScript in the "toAddr" AppleScript variable (which is created and populated at the same time.

Global fields do not need the "of current record" as they are the same for all records. They still need to be on the layout however. Unless you specify them by layout name or table (occurrence) name.

Link to comment
Share on other sites

One thing I've noticed in several of your code quotes. You have a line:

the theMessage

where it should be:

tell theMessage

That is likely why you had to add the "at theMessage" to your recipient line. Because "the theMessage" does nothing, so it did not know which message to add the recipient to. Either works. That is you can say:

tell object

  do something

end tell

or

do something at object

or

tell object to do something

AppleScript is flexible this way. Hence you can have two sets of code that do the same thing, but are written quite differently. It's just a different form of nesting.

To keep your life simple I recommend putting all the fields you're going to use in AppleScript on a dedicated layout. Then flip to that layout when the AppleScript is running. Then back (if desired). That way you can use the simplest form of syntax to target FileMaker fields; ie., no references to layout or table are needed within the AppleScript.

You pass data to AppleScript via FileMaker fields, including global fields. AppleScript cannot see script Variables.

set toAddr to cell "Email_address" of current record

That's it. "Email_address" is a FileMaker local field on the layout. It has been passed to the AppleScript in the "toAddr" AppleScript variable (which is created and populated at the same time.

Global fields do not need the "of current record" as they are the same for all records. They still need to be on the layout however. Unless you specify them by layout name or table (occurrence) name.

I have it working. I am using the "native Applescript" dialogue in FM pro with the following script in it:

set toAddr to cell "ass_pers_email" of current record

set theSubject to cell "Mattername" of current record

set theContent to "This email is desgined to test the script"

tell application "Microsoft Outlook"

set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent}

the theMessage

make new to recipient at theMessage with properties {email address:{address:toAddr}}

open theMessage

end tell

Where "ass_pers_email" is the email address of the person associated with the record

and mattername is a unique field in each record

the script provides me with a draft email with the "to" and "subject" completed - just what I wanted.

Thanks for your help.

Link to comment
Share on other sites

I have it working. I am using the "native Applescript" dialogue in FM pro with the following script in it:

set toAddr to cell "ass_pers_email" of current record

set theSubject to cell "Mattername" of current record

set theContent to "This email is desgined to test the script"

tell application "Microsoft Outlook"

set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent}

the theMessage

make new to recipient at theMessage with properties {email address:{address:toAddr}}

open theMessage

end tell

Where "ass_pers_email" is the email address of the person associated with the record

and mattername is a unique field in each record

the script provides me with a draft email with the "to" and "subject" completed - just what I wanted.

Thanks for your help.

As ever, having nailed the last problem I now need to know how to separate email addresses so as to have more than email address in the toAddr.......

Link to comment
Share on other sites

As ever, having nailed the last problem I now need to know how to separate email addresses so as to have more than email address in the toAddr.......

solved that:

set toAddr to cell "ass_pers_email" of current record

set toSnr_Associate to cell "Snr_Ass_email" of current record

set toSolicitor to cell "Solicitor_email" of current record

set theSubject to cell "Mattername" of current record

set theContent to cell "partner_first_name" of current record

tell application "Microsoft Outlook"

set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent}

the theMessage

make new to recipient at theMessage with properties {email address:{address:toAddr}}

make to recipient at theMessage with properties {email address:{address:toSnr_Associate}}

open theMessage

end tell

Link to comment
Share on other sites

  • Newbies

This is such a great post. I have been stuggling with this problem since day one. My question is that I can't figure out how to make this work with my database. Here is what I've come up with, but I get errors.

set toAddr to cell "HO EMAIL Add LIST" of current record

set theSubject to cell "PO email subject" of current record

set theContent to cell "PO email Message" of current record

tell application "Microsoft Outlook"

set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent}

the theMessage

make new to recipient at theMessage with properties {email address:{address:toAddr}}

open theMessage

end tell

My fields that I pull the data from are the ones in " " 's. What am I doing wrong?

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

This topic is 4819 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.