ChangeAgent Posted March 10, 2009 Posted March 10, 2009 I need a script to send an email to a person and take, at random, the text out of a specific field in a FMP 8 data base. I am not good at scripting and so far my attempts have failed. Does anybody have any ideas? Here is the mail script I use that works fine to sent fixed text: set theSubject to "Subject text" --change me set theBody to "Body text" --change me set theTarget to "[email protected]" --change me tell application "Mail" set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody} tell newMessage make new to recipient at end of to recipients with properties {address:theTarget} set sender to "Me " --change me end tell send newMessage end tell but not sure how to get to the field in in my data base and select one randomly.
Osman Posted March 10, 2009 Posted March 10, 2009 Why don't you use send mail script step? As I remember, it was added with version 7.
ChangeAgent Posted March 10, 2009 Author Posted March 10, 2009 I want to use my mailing list to send a quote every day from my FMP database. I think this can only be done from the outside of the DB as it contains no email addresses. so the mail script step would not help.
comment Posted March 10, 2009 Posted March 10, 2009 How about something like: Go to Layout [ Quotes ] Show All records Go to Record [ Ceiling ( Random * Get (FoundCount) ) ] Perform AppleScript
ChangeAgent Posted March 10, 2009 Author Posted March 10, 2009 I tried this, but it hangs on 'Show All records' last word not sure how to fix.
ChangeAgent Posted March 10, 2009 Author Posted March 10, 2009 fixed that by using: end tell tell application "FileMaker Pro Advanced" show every record in database "Quotes" -- works still not sure how to get it to select a random record and copying it. BTW, rest of your code does not work either. hangs already on the field/layout selection.
ChangeAgent Posted March 10, 2009 Author Posted March 10, 2009 oops did not realise. Go to Record [ Ceiling ( Random * Get (FoundCount) ) ] does not work. Get: Specified field table can not be found
comment Posted March 10, 2009 Posted March 10, 2009 I am not sure what you're doing. You need to open Scriptmaker and create a new script with the steps I have outlined. In the step Go to Record (or more precisely, Go to Record/Request/Page), specify 'By calculation...', and enter: Ceiling ( Random * Get (FoundCount) ) into the calculation window.
ChangeAgent Posted March 10, 2009 Author Posted March 10, 2009 yes, I am in Scriptmaker and have made a new script. Now I understand your instructions and it works. Not sure what I did wrong so far, but never mind, thanks for your patience. however I need to enter a number and would like it to be automatically and random generated. Is this possible?
comment Posted March 10, 2009 Posted March 10, 2009 The script selects a random record from all the records in the table. I am not sure why you would need to enter a number for this.
ChangeAgent Posted March 11, 2009 Author Posted March 11, 2009 it does though, have a look: http://www.imageno.com/zis10bi647x3pic.html
comment Posted March 11, 2009 Posted March 11, 2009 Select the option "Perform without dialog' for the Go to Record/Request/Page step.
ChangeAgent Posted March 11, 2009 Author Posted March 11, 2009 ah, of course! thanks a million! I now need to see if I can build a Applescript around this.
comment Posted March 11, 2009 Posted March 11, 2009 You could have the Filemaker script run your Applescript as its final step. If you want to run this from "outside", have your Applescript call the FM script, then proceed with the data from the current record.
ChangeAgent Posted March 11, 2009 Author Posted March 11, 2009 Thanks that was what I was planning to do, will experiment later when I am back on the machine that has the DB
ChangeAgent Posted March 11, 2009 Author Posted March 11, 2009 thanks for your help comment, in case anybody else is following this and interested, here is the Applescript that works, adjust as needed to point to the FMP file and where ever you want to paste it to. I activated the script in FMP8, by giving it 'CMD 1' as a key command. So the Applescript triggers the FMP script and takes the copied contents and pastes it, in this case in a new TextEdit document. tell application "Finder" activate open document file "X" of folder "Y" of disk "Z" tell application "System Events" tell application "FileMaker Pro Advanced" to activate keystroke "1" using command down end tell end tell delay 3 try set the clipboard to Unicode text of (the clipboard as record) on error errMsg display dialog errMsg end try tell application "TextEdit" activate delay 0.5 tell application "System Events" key code 48 using {command down} key code 9 using {command down} end tell end tell
comment Posted March 11, 2009 Posted March 11, 2009 Why not simply something like: tell application "FileMaker Pro Advanced" open "HD: ... Quotes.fp7" do script "Random Quote" set dailyQuote to cellValue of cell "Quote" of current record end tell tell application "Another Application" set some object to dailyQuote ... I am not sure that's the correct syntax - all I am trying to say that you can address objects directly, instead of trying to emulate mouse clicks and keyboard presses.
ChangeAgent Posted March 11, 2009 Author Posted March 11, 2009 cool works too! only problem is it puts the quote in quotation (") marks.
Recommended Posts
This topic is 6105 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 accountSign in
Already have an account? Sign in here.
Sign In Now