Assign a variable multiple values and run an If-Or-And command

Hi,

I am trying to parse out a text file (.ics actually) to input the result into iCal.

I have a subroutine in my script which handles any “ALL Day” events. These all day events are indicated in my text file (clipboardText) as either “A” or “G” or “L” or “LJ” or “EXB” or “O” or “U”.

Currently, I use independent If-Then statements to identify the string.

if word 3 of clipboardText is "A" then
				AllDayEvents(clipboardText)
			else
				if word 3 of clipboardText is "G" then
					AllDayEvents(clipboardText)
				else
					if word 3 of clipboardText is "L" then
						AllDayEvents(clipboardText)
					else
						if word 3 of clipboardText is "LJ" then
							AllDayEvents(clipboardText)
						else
							if word 3 of clipboardText is "EXB" then
								AllDayEvents(clipboardText)
							else
								if word 3 of clipboardText is "O" then
									AllDayEvents(clipboardText)
								else
									if word 3 of clipboardText is "U" then
										AllDayEvents(clipboardText)

Is there a way to assign a variable to all the “AllDayEvents” string values and combine the If-Then statements into one?

I also have a situation where I need to question 2 string values in the same If-Then statement:

if word 12 of clipboardText is "PX" and word 28 of clipboardText is "PX" then																	MultiplePXDutyFlights(clipboardText)

My problem is that the string “PX” above could be “PX” or “AL” or “RQ” or “RP” etc. When I attempt to include all the variables in the If-Then statement by saying “or” it errors. To reduce the amount of If-Then statements I have to make and to clean up my script, is there a way to assign a variable to all of the aforementioned string values and combine them into a single If-Then statement?

Regards,

Kevin

Model: iMac
AppleScript: Version 2.4 (128)
Browser: Safari 534.48.3
Operating System: Mac OS X (10.7)

For your first question you can do this…

set allDayEventCodes to {"A", "G", "L", "LJ", "EXB", "O", "U"}
if word 3 of clipboardText is in allDayEventCodes then AllDayEvents(clipboardText)

For your second question do something similar. Set all the possible values into a list and use an if statement and the command “is in” to check against the values in the list.

PERFECT!

Thank you very much.

:slight_smile: