What I’m doing is creating lists for each of the properties of the date string (Weekday, Month, Day, Year) that are relavent to my scripting needs. I list each potential property value as a key, and assign it a unique string as it’s value. I am having trouble dynamically accessing a key by name and being able to retrieve it’s value.
I’ve create a list of key/value pairs as a property variable in the head of my script. I’ll work here with only the “Weekday” property, as the rest will use the same process on their respective properties of the date string.
property WeekdayValuesList : {|Monday|:"1", |Tuesday|:"2", |Wednesday|:"3", |Thursday|:"4", |Friday|:"5", |Saturday|:"6", |Sunday|:"7"}
Then, later in the script I get the current date (or any other date) and split it up into four variables representing each of the properties listed above. This is no problem, I have the values for each of the current date properties ready to go in string form…
set originalWeekday to weekday of theCurrentDate as string
But then, I want to use each of these variables to dynamically reference the appropriate list, and set a second variable to the value of the list item that matches the key. For example, if the current weekday is “Saturday”, I want to get the value of the key “Saturday” from the ‘WeekdayValuesList’ (which is 6), and set it as the value for the variable ‘modifiedWeekday’. I can access the values by hard-coding the reference to them with…
set modifiedWeekday to |Monday| of WeekdayValuesList
But what I want to do is something to th effect of…
set modifiedWeekday to originalWeekday of WeekdayValuesList
I have tried many variations on this code and cannot get a variable to access the key/value pairs. I am not sure if the problem is caused by the fact that I am referencing predefined AS variables, or if my coding is just ugly.
Any thoughts?..Thanks in advance…
j