Extracting element of current time chosen from a list

I am having trouble getting this simple script to work -

set TimeParams to {"date string", "year", "month", "day", "weekday", "time string", "hours", "minutes", "seconds"}
set ChosenTimeParam to (choose from list TimeParams)
display dialog "The ChosenTimeParam is " & ChosenTimeParam giving up after 2
set timeinfo to {ChosenTimeParam of (current date)} -- as string --NOT WORKING!!!
display dialog "The " & ChosenTimeParam & " is " & timeinfo giving up after 3

Result:
error “Can’t get ChosenTimeParam of date "Wednesday, May 25, 2011 3:28:07 PM".” number -1728 from ChosenTimeParam of date “Wednesday, May 25, 2011 3:28:07 PM”

I have tried adding "as string"in various combinations. Nothing seems to work.
Any help will be appreciated!
…Al

Model: iMac 2008
AppleScript: 2.3
Browser: Firefox 4.0.1
Operating System: Mac OS X (10.6)

Your problem is that the key word required in the command is a string from the list, not an unquoted keyword. Although you can run text scripts, you can’t run them from a variable, so even something like this doesn’t work:

set TimeParams to {"date string", "year", "month", "day", "weekday", "time string", "hours", "minutes", "seconds"}
set CD to " of current date"
set ChosenTimeParam to (choose from list TimeParams)
display dialog "The ChosenTimeParam is " & ChosenTimeParam giving up after 2
set tScript to (ChosenTimeParam & CD) as text -- this will be OK
set timeinfo to run script tScript as text -- this will fail.
display dialog "The " & ChosenTimeParam & " is " & timeinfo giving up after 3

You can do this sort of thing:

set TimeParams to {short date string of (current date), year of (current date), month of (current date), day of (current date), weekday of (current date), time string of (current date)}
choose from list {"1 Short Date String", "2 Year", "3 Month", "4 Day", "5 Weekday", "6 Time String"}
set timeinfo to item ((first character of (result as string)) as integer) of TimeParams

Actually, you can run text scripts from variables provided the scripts are absolutely correct! In this case, you need to insert the parentheses around ‘current date’:

set TimeParams to {"date string", "year", "month", "day", "weekday", "time string", "hours", "minutes", "seconds"}
set CD to " of (current date)" -- NB. parentheses.
set ChosenTimeParam to (choose from list TimeParams)
display dialog "The ChosenTimeParam is " & ChosenTimeParam giving up after 2
set tScript to (ChosenTimeParam & CD) as text -- this will be OK
set timeinfo to run script tScript
display dialog "The " & ChosenTimeParam & " is " & timeinfo giving up after 3

Ahh, I thought you could, but couldn’t figure out what was failing at 9 in the evening. Thanks.

@Nigel & Adan -
Thank you! The subtleties of AppleScript are truly amazing.
…Al

Slight simplification - extra variable CD not needed …

set TimeParams to {“date string”, “year”, “month”, “day”, “weekday”, “time string”, “hours”, “minutes”, “seconds”}
set ChosenTimeParam to (choose from list TimeParams)
set tScript to (ChosenTimeParam & " of (current date)") as text
set timeinfo to run script tScript
display dialog "The " & ChosenTimeParam & " is " & timeinfo giving up after 3