Jump to content

RE : Applescript Functions??


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

Recommended Posts

Hi there,

Just wondering if someone could help me with something.

Say I have an Applescript which has some variables in it such as emailSubject, emailMessage etc...

How can I easily call this script from Filemaker instead of typing the whole thing in and at the same time as calling it pass in the emailSubject, emailMessage variables from data supplied via Filemaker fields.

I would like to basically be able to pass data from Filemaker to the script.

The script would be used for emailing and as I want different details each time I do not want to have to hard code in the variables as they will need to be dynamically generated via Filemaker.

Any help with this would be greatly appreciated as I have been trying to do this all day with no joy at all. The only thing I noticed was that you can have B)

property name :) "My Name"

and so on but I couldn't find a way of getting the part in the inverted commas to be fields from Filemaker.

Thanking anyone in advance for any help with this.

Regards,

Mark Bowen

Link to comment
Share on other sites

First, you'd be running this in a Perform AppleScript script step, I assume. Or is it a stand-alone AppleScript applet?

It's quite easy to pass values. It depends however on the overall structure of the logic. Are you running Perform AppleScript while Looping through records? Then you'd pass the values from the current record each time.

Or are you passing all the values from the FileMaker found set, then using an AppleScript repeat, going through the list? In which case you'd use a different syntax.

For passing a value from the current record (in which case I don't think you'd want to put it in a property, which is for more constant values)B)

set theSubject to cell "emailSubject" of current record

You must understand the difference between a "window", "document" or database" object (they are different, but with some overlap; basically window or document is the found set; but "document 1" is NOT necessarily the frontmost document (it's the 1st opened that session; gak).

Link to comment
Share on other sites

Yes, that's another method, the calculated AppleScript; which is similar to the Calculation Field AppleScript. Which is a lot easier to write in 7, with the Quote() function, as you used, or the " - much better than the old """", or is it """ for this one? (gak B)-)

Several different ways. I tend to use regular AppleScript text in a Perform AppleScript step for anything that's more than a few lines long. Mostly I write my AppleScripts in Script Editor, to see the syntax coloring and indentation, and to test (with highlighting of the offending syntax).

Then I copy/paste the text into FileMaker's Perform AppleScript, after --commenting out the relevant: tell application "FileMaker Developer" and its end tell. Those lines are not needed or wanted within FileMaker, unless nested within another app's tell block. But they are needed in Script Editor; often they are the first and last lines, so it's easy enough to --comment them.

Link to comment
Share on other sites

Hi Fenton & Reed,

Thanks for all the info. This was actually an applescript application that I wanted to launch whilst passing values to it.

I need to make a very simple emailer for our company so that we can email files to people.

I would need to pass the emailSubject, emailMessage, emailSender, emailRecipient and filePath to the application so that it can work with these values. All of the fields are Global fields so not a problem with current record or anything like that.

Actually last night (very very late) I happened across an Applescript that set up the variables exactly as you stated Fenton so I was going to post this morning anyway so that people wouldn't spend too long answering but maybe to answer if there was a better way.

Thankyou very very much for all the information.

Regards,

Mark

Link to comment
Share on other sites

Hi again,

Got most of it working now. The only problem I am having is that I want to pass the script a filePath to use instead of using a :)

set theAttachment to (choose file with prompt "Choose the file to attach to the message...")

I have tried :

set theAttachment to cell "filePath" of current table

and the filePath is a (definitely) valid path to a file on the computer but it just keeps on saying file not found.

I am guessing that the choose file with prompt part returns the file name as something other than just a string but I just don't know what that is and don't know how to set it!

If anyone understands this and can help me with it I would be exceptionally grateful.

This (I am pretty sure) is the only part that I need now and then my little app should be ready for unleashing on my work colleagues!! B)

Thanks again for all the help and any help that you might be able to impart to me on this.

Regards,

Mark

Link to comment
Share on other sites

Hi there,

As an update I thought I would show one of the scripts that I am currently working on B)

set theSubject to cell "emailSubject" of current table

set theMessage to cell "emailMessage" of current table

set theRecipient to cell "emailRecipient" of current table

set theAttachment to cell "filePath" of current table

set theSender to cell "emailSender" of current table

tell application "Mail"

activate

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

tell newMessage

set sender to theSender

make new to recipient at end of to recipients with properties {address:theRecipient}

tell content

make new attachment with properties{file name:alias “Hard Disk:Users:something2add:Desktop:Kiosk Orbs.jpg”} at after the last paragraph

end tell

send newMessage

end tell

end tell

The parts in bold are where I thought I would be able to write this :)

make new attachment with properties{file name:alias theAttachment} at after the last paragraph

but it just doesn't work. The email gets sent but without an attachment.

Any thoughts on this would be greatly appreciated.

P.S. This script uses the Mail application as you can tell but my previous post in this message was using the xMail scripting addition. If anyone has ideas on either of these and as to why they won; work then I will be forever in your debt.

Thanks once again for any knowledge imparted on this.

Regards,

Mark

Edited by Guest
Link to comment
Share on other sites

Outside the Finder:

Doesn't work: alias "the file path"

Works: "the file path" as alias

Inside the Finder either works:

tell app "Finder"

alias "the file path"

end tell

tell application "FileMaker Developer"

set theAttachment to (cell "filePath" of current record)

end tell

tell app "Mail"

[snip]

make new attachment with properties{file name: theAttachment as alias}

end tell

[i would think you want "current record" rather than "current table" (which is more or less the default, whereas current record is not, 1st record is).]

You could alternatively try to set "as alias" up in the FileMaker block. Setting the theAttachment to an alias (or file) reference right away will cause an AppleScript error if the file is not there. It depends where you want the script to stop if the attachment's missing, before or after creating the message. I'd think before.

(For one thing I couldn't even see the message otherwise, unless I added: save message when I didn't want to send right then. In other words, you can control what happens on failure, but you have to decide what.)

Link to comment
Share on other sites

Fenton,

You are an absolute genius. A true star!!!

I set it to B)

file name :) theAttachment as alias

and it all works great!!!

Thanks

Here is the full code in case anyone is interested :

set theSubject to cell "emailSubject" of current table

set theMessage to cell "emailMessage" of current table

set theRecipient to cell "emailRecipient" of current table

set theAttachment to cell "filePath" of current table

set theSender to cell "emailSender" of current table

tell application "Mail"

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

tell newMessage

set sender to theSender

make new to recipient at end of to recipients with properties {address:theRecipient}

tell content

make new attachment with properties{file name:theAttachment as alias} at after the last paragraph

end tell

send newMessage

end tell

end tell

Thanks again Fenton. You are absolutely brilliant and a life saver!!

Best wishes,

Mark

Link to comment
Share on other sites

Hi there,

Just wondering on one last thing if anyone had any ideas as to how I could possibly copy the message body text from a field in filemaker and then paste that into the body of the email instead as when doing it using the 'set theMessage' syntax all formatting is lost.

Also does anyone know why 'Mail' on OSX is scriptable but if you go into the Apple Script Editor and press record it doesn't actually record anything??

Thanks for all the help.

Regards,

Mark

Link to comment
Share on other sites

  • 1 month later...

Thanks to Mark and Fenton. Your exchange has helped me with my own emailing solution, which is now working great.

Another related question. I see that "Mail" has a check box in the Attachment dialogue box for sending Windows friendly attachments. Do you know if there is a line of AppleScript that can be added to the AppleScripts discussed here that will send window friendly attachments.

Thanks in advance for your help - Sam

Link to comment
Share on other sites

This topic is 6806 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.