Checking to make sure the correct folder was choosen

I want to check and make sure the user of this script chooses the correct folder. The folder name will always be the same “JOBS” but the path, location, will always be different. How can I check to make sure the user selected the JOBS folder?

something like this i’m thinking

try
set thePath to choose folder (path to) with prompt “Please select the JOBS folder for the intended client”
if thePath is not “JOBS” then
error
else
“do this”
end if
on error
display dialog “Please make sure you choose the JOBS folder”
end try

This should do it for you.

repeat
	set thePath to choose folder with prompt "Please select the JOBS folder for the intended client"
	if name of (info for thePath) is "JOBS" then exit repeat
end repeat

Is the folder in the same place on each machine? (Ex. on the Desktop, in the Documents folder? - If this is a workflow, it should be.)

If they are in the same place, then why let them choose? I’d go even further and say, DON’T LET THEM CHOOSE! You direct them where you want them to go or they’ll go wherever they want! Then you’ll be stuck trying to write exceptions for each user and/or machine.

Jim Neumann
BLUEFROG

P.S. Regarding your code. the sentiment is right, the syntax is wrong.


set thepath to choose folder with prompt "Choose a job"
if (thepath as Unicode text) does not contain "Jobs" then -- The return is an alias so I coerced so I could see if it contained "Jobs"
	display dialog "Error"
else
	display dialog "Found"
end if

Of course, James slips in while I’m previewing my post.:stuck_out_tongue:

Stefan loves to do that to me :smiley:

I do agree with you btw on your thoughts concerning work flow =)

You guys are great! That’s just what I needed.

I agree also that not letting them choose is the best way to go but I’m afraid that’s a bit out of my league at this point. The folders live on a RAID volume and the folders are within an alphabetical listing. So for example, we have folders A thru Z. ABC Company is located in the A folder, Zebra Company is located in the Z folder and so on. The JOBS folder is then located inside the company folder /A/ABC Company/JOBS

If you’d like to attempt it I’m all eyes. But what you gave me will work great.

Thank You!
rjewer

I’m with Jim Neumann – use a dialog to get the company name from them, you do the rest in the script.

Here is a quick and dirty way to eliminate some user error. This will build a client list at run time and prompt the end user to select the client. The path to the job folder is then built.

-- set the raid path here
set raidPath to path to desktop as Unicode text
set raidPath to (raidPath & "RAID")
--

set posixraidPath to quoted form of POSIX path of raidPath
set clients to paragraphs of (do shell script "find " & posixraidPath & " -type d -mindepth 2 -maxdepth 2")
set clientList to {}

tell application "Finder"
	repeat with i from 1 to count of clients
		set end of clientList to name of folder ((POSIX file (item i of clients)) as alias)
	end repeat
	
	set theClient to item 1 of (choose from list clientList with prompt "Please select the client")
	
	set thepath to raidPath & ":" & (character 1 of theClient) & ":" & theClient & ":" & "JOBS" as alias
end tell

And here is another version. This one displays client names in the format of First Letter/Client name (C/Callaway and A/ABC) in the select dialog. This makes building the path easier in the case of a client folder being named “The Harring Group”, but being filed under “H”. This would cause the previous version to fail.

-- set the raid path here
set raidPath to path to desktop as Unicode text
set raidPath to (raidPath & "RAID")
--

set posixraidPath to POSIX path of raidPath
set clients to paragraphs of (do shell script "cd " & quoted form of posixraidPath & ";find ./ -type d -mindepth 2 -maxdepth 2")
set clientList to {}

tell application "Finder"
	repeat with i from 1 to count of clients
		set end of clientList to text 4 through -1 of item i of clients
	end repeat
	
	set theClient to item 1 of (choose from list clientList with prompt "Please select the client")
	set thepath to ((POSIX file (posixraidPath & "/" & theClient & "/JOBS")) as alias)
end tell