March 10, 200916 yr 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.
March 10, 200916 yr Why don't you use send mail script step? As I remember, it was added with version 7.
March 10, 200916 yr Author 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.
March 10, 200916 yr How about something like: Go to Layout [ Quotes ] Show All records Go to Record [ Ceiling ( Random * Get (FoundCount) ) ] Perform AppleScript
March 10, 200916 yr Author I tried this, but it hangs on 'Show All records' last word not sure how to fix.
March 10, 200916 yr Author 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.
March 10, 200916 yr Author oops did not realise. Go to Record [ Ceiling ( Random * Get (FoundCount) ) ] does not work. Get: Specified field table can not be found
March 10, 200916 yr 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.
March 10, 200916 yr Author 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?
March 10, 200916 yr 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.
March 11, 200916 yr Select the option "Perform without dialog' for the Go to Record/Request/Page step.
March 11, 200916 yr Author ah, of course! thanks a million! I now need to see if I can build a Applescript around this.
March 11, 200916 yr 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.
March 11, 200916 yr Author Thanks that was what I was planning to do, will experiment later when I am back on the machine that has the DB
March 11, 200916 yr Author 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
March 11, 200916 yr 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.
Create an account or sign in to comment