store script: passing a variable's value instead of its name

Hi all,

I would like to write a script that does something like this…

  1. Prompt for a date which I call “deadline” and a name that I call “filename”.
  2. Create a script object named “mail_reminder_2_weeks”. On run, this script creates and sends a message through Mail. The subject of the email is "Reminder: " & filename & " filing deadline is " & deadline
  3. Store the script on disk; the script will be run when an iCal open file alarm is activated on a date that I specify.

This is the script that I make.

script mail_reminder_2_weeks
tell application “Mail”
set message_2_weeks to make new outgoing message
set subject of message_2_weeks to “Reminder: " & filename & " filing deadline is " & deadline
set visible of message_2_weeks to false
set content of message_2_weeks to “nothing here”
set sender of message_2_weeks to “My Name myname@mac.com
tell message_2_weeks
make new to recipient at end with properties {name:“My Name”, address:"myaddress@gmail.com”}
end tell
send message_2_weeks
end tell
end script

store script mail_reminder_2_weeks in (folder_path & “:” & (name of mail_reminder_2_weeks as string))

My problem is that the stored script does not know the values of the variables that were in effect when I wrote the script object (definition of the variables not shown in script). For instance, if name is “John Smith” and deadline is “January 1, 2007”, then I want the script to say

set subject of message_2_weeks to "Reminder: " & “John Smith” & " filing deadline is " & “January 1, 2007”

How can I replace the names of the variables with their values in the stored script?

Thanks,
Matt

Hi,

use script properties like

script mail_reminder_2_weeks
	property filename : ""
	property deadline : ""
	tell application "Mail"
		set message_2_weeks to make new outgoing message
		tell message_2_weeks
			set subject to "Reminder: " & filename & " filing deadline is " & deadline
			set visible to false
			set content to "nothing here"
			set sender to "My Name <myname@mac.com>"
			make new to recipient at end with properties {name:"My Name", address:"myaddress@gmail.com"}
		end tell
		send message_2_weeks
	end tell
end script

set mail_reminder_2_weeks's filename to "theName"
set mail_reminder_2_weeks's deadline to "theDate"

store script mail_reminder_2_weeks in file (folder_path & ":mail_reminder_2_weeks.scpt")

Stefan,

Thanks so much. That’s exactly what I was looking for.

Matt