Compare Choice to List

Hello all,

I need to compare a choice from a drop down list to a folder name. I am attaching my script. My company’s folder structure stays the same month-to-month but the date part of the folder name will change so I am trying to compare just the text part of folder name with a drop down.

set titleList to {"AF", "BT", "CF", "DF", "FER", "HI", "HF", "REP", "WB"} --ETC
choose from list titleList with prompt "Choose the title you are shipping." default items "REP"
set chosenItem to result
if chosenItem is false then
	error number -128
else
	set chosenItem to item 1 of chosenItem
end if

--set magFolderPath to alias "Dev Mac:Users:Dev:Desktop:Folder1:"
set theList to list folder magFolderPath without invisables

repeat with i from 1 to count of items of theList
	set fileName to item i of theList as text
	if fileName contains (chosenItem as text) then
		set titleFolder to alias (magFolderPath & fileName)
	end if
end repeat

I need to check if “REP” is selected then compare to all folders and find that “REP200407” matches and change magFolderPath to Dev Mac:Users:Dev:Desktop:Folder1:REP200407.

I do not understand why this doesn’t work? Any help is most appreciated.

Thank you,
Steven.

  1. ‘invisibles’ should be spelt with three “i”'s. :wink:

  2. The value of your variable 'magFolderPath" is an alias. You need to coerce this to string before contatenating the file name:

set titleFolder to alias ((magFolderPath as string) & fileName)

Big whoops on the spelling - never one of my strong points. Thank you for that.

O.K., I got the comparison working with

repeat with i from 1 to count of items of theList
	set fileName to item i of theList as text
	if fileName contains (chosenItem as text) then
		set titleFolder to ((magFolderPath & fileName) as text)
	end if
end repeat

Now, my next hurdle is showing only text documents from a folder list and making them available in a drop down list selection. I have this much and it works but I do not know how to limit the results to just text. I tried ". . . of type {“TEXT”} but that errors.

set adRunListPath to (titleFolder & ":Display Ad:")
set adList to list folder adRunListPath
set dropDownList to every item of adList --whose file type is {"TEXT"}
choose from list dropDownList with prompt "Choose the Export for this section."
set chosenItem to result
if chosenItem is false then
	error number -128
else
	set filepath to (adRunListPath & chosenItem)
	set aList to read file filepath as text using delimiter return
end if

Any help on the limit of drop down list items to just text docs would be great.

Thank you for the help so far.
Steven.

I had a little blip myself with my spelling of “concatenation”. :wink:

I’d use the Finder to identify the text files in the folder and to get their names for the ‘choose from list’ dialog:

set adRunListPath to (titleFolder & ":Display Ad:")
tell application "Finder"
  set textFileNames to name of every file of folder adRunListPath whose file type is "TEXT"
end tell
set chosenItem to (choose from list textFileNames default items {item 1 of textFileNames})
-- etc.

That’s on the assumption you’re not using Mac OS X. If you are using X (and the magFolderPath in the other excerpt suggests that you may be) — you’ll need to modify that to something like:

set adRunListPath to (titleFolder & ":Display Ad:")
tell application "Finder"
  update items of folder adRunListPath
  set textFileNames to name of every file of folder adRunListPath whose file type is "TEXT" or ¬
    name extension is in {"txt", "html", "csv"} -- etc., whatever extensions you're expecting
end tell
set chosenItem to (choose from list textFileNames default items {item 1 of textFileNames})
-- etc.

That worked! It also moved me along to the next part of my script I can not get working!

I created a new post for that problem.

Thank you very much for the suggestion. It always seems to be a little thing I miss (or a really big thing).

Steven.