Type of object from list

It’s been a long time since I touched AppleScript and so this might be me just not doing things right. I have a list that I create by collecting the second to the last text item in a path. The path would look something like this:

HD:Users:xxxxxxxx:Library:Developer:Xcode:Archives:2017-06-14:focus 6-14-17, 8.03 AM.xcarchive:"

and so the list is populated with strings that look something like this: focus 6-14-17, 8.03 AM.xcarchive

I then present to the user and ask them to select an archive. I have another list that contains all the archive paths. What I am looking to do is take the selected archive, find out it’s index in the archive name list and then pull the path from the archive path list. Pretty straight forward, at least I thought. The relevant part of the code looks like this:

set myFile to choose from list archiveFileNames with prompt "Select An Archive"
	-->return class of myFile
	
	repeat with i from 1 to count of every item of archiveFileNames
		
		if (myFile is equal to (item i of archiveFileNames as string)) then
			log myFile & "::" & item i of archiveFileNames & "::" & i
		end if
	end repeat

I never got a match, even though if I just repeat through the archive name list and use a log statement I can get results that I am looking for:

log myFile & "::" & item i of archiveFileNames & "::" & i

(See last result for the match)

(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 5-1-17, 1.40 PM.xcarchive, ::, 1*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 5-1-17, 10.48 AM.xcarchive, ::, 2*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 5-1-17, 11.04 AM.xcarchive, ::, 3*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 5-1-17, 11.24 AM.xcarchive, ::, 4*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 5-1-17, 9.37 AM.xcarchive, ::, 5*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 5-3-17, 2.01 PM.xcarchive, ::, 6*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 5-3-17, 2.02 PM.xcarchive, ::, 7*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 5-5-17, 2.51 PM.xcarchive, ::, 8*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 5-12-17, 8.49 AM.xcarchive, ::, 9*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 5-12-17, 8.53 AM.xcarchive, ::, 10*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 5-16-17, 11.43 AM.xcarchive, ::, 11*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 6-5-17, 1.42 PM.xcarchive, ::, 12*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 6-6-17, 10.37 AM.xcarchive, ::, 13*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 6-6-17, 4.09 PM.xcarchive, ::, 14*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 6-13-17, 4.01 PM.xcarchive, ::, 15*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 6-14-17, 11.36 AM.xcarchive, ::, 16*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 6-14-17, 8.00 AM.xcarchive, ::, 17*)
	(*focus 6-14-17, 8.03 AM.xcarchive, ::, focus 6-14-17, 8.03 AM.xcarchive, ::, 18*)

So I thought this must be a class/type issue where there is no equality because I am comparing apples and oranges. When I run it and have -->return class of myFile uncommented, I get that the class of my selection from the list is a list.

Obviously I am doing something wrong. I was expecting the type to be string, maybe text, not list. Help me Obi Wans, you are my only hope! :smiley:

choose from list returns a list of the chosen items, even when there’s only one. The command also has a pecularity whereby it returns false if the Cancel button’s clicked instead of generating the “User canceled” error, so you have to do that yourself:

set theChoice to (choose from list archiveFileNames with prompt "Select An Archive")
if (theChoice is false) then error number -128 -- "User canceled" error
set myFile to item 1 of theChoice -- Get the first (only) item from the list.

You might find this subroutine useful. The subroutine was by Emmanuel Levy with mods by Yvan Koenig. Simply submit the item chosen from your list and the list to the routine to get the position of the item. Then get the item at that position in your other list. Here’s a small implementation:


set myList to {"one", "two", "three", "four"}
set matchList to {"-1-", "-2-", "-3-", "-4-"}

set thePosition to indexOf("three", myList)
get item thePosition of matchList

on indexOf(theItem, theList)
	set oTIDs to AppleScript's text item delimiters
	set AppleScript's text item delimiters to return
	set theList to return & theList & return
	set AppleScript's text item delimiters to oTIDs
	try
		-1 + (count (paragraphs of (text 1 thru (offset of (return & theItem & return) in theList) of theList)))
	on error
		0
	end try
end indexOf