UNIX ls command in applescript

The goal is to take data on the ciipboard to search for a file.
Say the clipboard is SUA40.
I need to open the folder that has that file.
I need to open the file.

here is a photo of the folder structure.
https://www.dropbox.com/s/nrtvgm0p4448gup/SU%20Scripts.png?dl=0

here is my code that is not working.
any help would be appreciated.
Did Apple kill the forum for applescript, Its not working. The code below came from someone there and it did work at first. Things changed on my end and now it does not work.

tell application "Finder"
	
	if text_returned starts with "SU" then
		if text_returned contains "SUA" then
			set producer_folder to "SUA - All Others"
		end if
	end if
	
	if text_returned starts with "SU" then
		if text_returned contains "SUB" then
			set producer_folder to "SUB - Biswell Scripts"
		end if
	end if
	
	
	if text_returned starts with "SU" then
		if text_returned contains "SUDH" then
			set producer_folder to "SUDH Dhinakaran, Sharon"
		end if
	end if
	
	if text_returned starts with "SU" then
		if text_returned contains "SUE" then
			set producer_folder to "SUE - Elliott Scripts"
		end if
	end if
	
	if text_returned starts with "SU" then
		if text_returned contains "SUJ" then
			set producer_folder to "SUJ Jordan Miller"
		end if
	end if
	
	if text_returned starts with "SU" then
		if text_returned contains "SUJA" then
			set producer_folder to "SUJA - Anderson, Jarrod"
		end if
	end if
	
	if text_returned starts with "SU" then
		if text_returned contains "SUK" then
			set producer_folder to "SUK - Kara Lavengood"
		end if
	end if
	
	if text_returned starts with "SU" then
		if text_returned contains "SUL" then
			set producer_folder to "SUL - Little Scripts"
		end if
	end if
	
	if text_returned starts with "SU" then
		if text_returned contains "SUM" then
			set producer_folder to "SUM - Miller Scripts"
		end if
	end if
	
	if text_returned starts with "SU" then
		if text_returned contains "SUMC" then
			set producer_folder to "SUMC - McWhorter, Christine"
		end if
	end if
	
	if text_returned starts with "SU" then
		if text_returned contains "SUR" then
			set producer_folder to "SUR - Renelle Roberts"
		end if
	end if
	
	if text_returned starts with "SU" then
		if text_returned contains "SUS" then
			set producer_folder to "SUS - Salon Scripts"
		end if
	end if
	
	if text_returned starts with "SU" then
		if text_returned contains "SUT" then
			set producer_folder to "SUT - Terri Simmons"
		end if
	end if
	
	
	if text_returned starts with "SU" then
		if text_returned contains "SUV" then
			set producer_folder to "SUV - Angell Vasko"
		end if
	end if
	
	
	repeat with a_character in text_returned
		if a_character is in the_alphabet then
			set the_producer_initials to the_producer_initials & a_character
		end if
	end repeat
	
	
	
	
	
	
	
	-- OPEN project SCRIPT folder
	try
		set the_SCRIPT_folder to (do shell script "ls -d '/volumes/DW/700Club/Features/SCRIPTS/'*' '" & the_producer_initials's quoted form & "/ ")
		set x to the_SCRIPT_folder
		open POSIX file the_SCRIPT_folder as alias
		set bounds of Finder window 1 to {766, 93, 1561, 847}
	end try
	
	
	
	-- OPEN project SCRIPT file
	try
		set the_SCRIPTS to (do shell script "ls '/volumes/DW/700Club/Features/SCRIPTS/'*' '" & the_producer_initials's quoted form & "/" & text_returned's quoted form & "' '*")
		display dialog "Found it" giving up after 1
		open POSIX file the_SCRIPTS as alias
		set bounds of Finder window 1 to {766, 93, 1561, 847}
		set file_exists to "1"
	end try
end tell

Some variables aren’t defined in your script so I started with instructions defining them then I made some cleaning.
May you check that what I got is really what you hope to get.

set the_alphabet to "abcdefghijklmnopqrstuvwxyz" # Is it what you wanted ?
set the_producer_initials to "" # Is it what you wanted?

set text_returned to "SUA40" # If I understand well it was suppsed to be in the clipboard

if text_returned starts with "SU" then
	if text_returned contains "SUA" then
		set producer_folder to "SUA - All Others"
	else if text_returned contains "SUB" then
		set producer_folder to "SUB - Biswell Scripts"
	else if text_returned contains "SUDH" then
		set producer_folder to "SUDH Dhinakaran, Sharon"
	else if text_returned contains "SUE" then
		set producer_folder to "SUE - Elliott Scripts"
	else if text_returned contains "SUJA" then
		set producer_folder to "SUJA - Anderson, Jarrod"
	else if text_returned contains "SUJ" then
		set producer_folder to "SUJ Jordan Miller"
	else if text_returned contains "SUK" then
		set producer_folder to "SUK - Kara Lavengood"
	else if text_returned contains "SUL" then
		set producer_folder to "SUL - Little Scripts"
	else if text_returned contains "SUMC" then
		set producer_folder to "SUMC - McWhorter, Christine"
	else if text_returned contains "SUM" then
		set producer_folder to "SUM - Miller Scripts"
	else if text_returned contains "SUR" then
		set producer_folder to "SUR - Renelle Roberts"
	else if text_returned contains "SUS" then
		set producer_folder to "SUS - Salon Scripts"
	else if text_returned contains "SUT" then
		set producer_folder to "SUT - Terri Simmons"
	else if text_returned contains "SUV" then
		set producer_folder to "SUV - Angell Vasko"
	end if
end if


repeat with a_character in text_returned
	if a_character is in the_alphabet then
		set the_producer_initials to the_producer_initials & a_character
	end if
end repeat


return {producer_folder, the_producer_initials}
--> {"SUA - All Others", "initials_SUA"}

When this part will be correctly defined, it will be time to look at the second part of your script.

Yvan KOENIG running High Sierra 10.13.4 in French (VALLAURIS, France) samedi 19 mai 2018 15:44:41

I’m not accustomed to jokers in shell commands but my understanding is that or use of * as a joker is wrong.

When I run the script I get :

do shell script "ls -d '/volumes/DW/700Club/Features/SCRIPTS/'*' ''SUA'/ "
		--> error "ls: /volumes/DW/700Club/Features/SCRIPTS/* SUA/: No such file or directory" number 1

I assume that you hoped that the asterisk will be replaced by “Setup - SU/” and that the instruction will open the folder “SUA - All Others”.

Yvan KOENIG (VALLAURIS, France) samedi 19 mai 2018 16:22:37

Shell scripts don’t belong within Finder tell blocks, and much of the posted code appears to serve no purpose related to your question. Try this:

try
set theTarget to (do shell script "find -E " & "/volumes/DW/700Club/Features/SCRIPTS/"'s quoted form & " -maxdepth 3 -type f -regex " & (".*" & (the clipboard) & ".*")'s quoted form) as POSIX file as alias
tell application "Finder" to open {theTarget's container, theTarget}
on error
"¿"
end

thanks everyone, I will try this at work on Monday.

here is how I know how to do it in Applescript but when you have 100 files or folders, the search is SLOOOOOOW. I learned UNIX ls does it in 0.0001 milliseconds

tell application "Finder"
	set the clipboard to "SUE40" as string
	
	
	set the_alphabet to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	set proj_prod to ""
	
	
	repeat with a_character in (the clipboard)
		if a_character is in the_alphabet then
			set proj_prod to proj_prod & a_character -- SUA40 returns SUA
		end if
	end repeat
	
	
	
	--set proj_prod to "SUA"
	set proj_code to (the clipboard)
	
	
	set x to every item in folder "Macintosh HD:Users:shawn:Desktop:700Club:Features:SCRIPTS:Setup - SU" whose name contains proj_prod
	set project_folder to x as alias
	
	try
		set y to every item in folder project_folder whose name contains proj_code
		set script_file to y as alias
		display dialog "Found " & proj_code & " script" & return & "Opening file and folder" giving up after 2
		open project_folder -- the folder that has the SUA40 file
		open script_file -- the file we are looking for
	on error
		display dialog "Seems " & proj_code & " does not exist" & return & "see project folder"
		open project_folder -- the folder that has the SUA40 file
	end try
end tell

Here it’s ls which does the job using a correct syntax.

set the clipboard to "SUE40"


set proj_code to (the clipboard)
set the_alphabet to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set proj_prod to ""


repeat with a_character in proj_code
	if a_character is in the_alphabet then
		set proj_prod to proj_prod & a_character -- SUE40 returns SUE
	end if
end repeat



set basePosix to quoted form of (POSIX path of "DW:700Club:Features:SCRIPTS:Setup - SU:" & proj_prod)

set the_SCRIPT_folder to (do shell script "ls -d " & basePosix & "*")
set x to the_SCRIPT_folder
--> "/Volumes/DW/700Club/Features/SCRIPTS/Setup - SU/SUE - Elliott Scripts"

Yvan KOENIG running High Sierra 10.13.4 in French (VALLAURIS, France) samedi 19 mai 2018 21:05:42

Mark Anthony, I made a mock up folder structure on my laptop with 200 files in the folder. The response was lightning fast. Thank you so much. I know this will work at work. I do audio post for television and we search for files over dozens of servers, a ton of folders and a million files (slightly exaggerated).

Your code will speed up the process of finding a file by several minutes for each search. Thank you so much. I am forever grateful.

Shawn