I’m trying to re-write a folder script that I’ve been using for years. I just want to clean up the code a bit, and add some features. I’ve tried to write some basic stuff, and I’ve hit a stumbling block.
So far, the code I’ve written should take a job number from the user and then check to see if that job number is used on our server already. There is a subroutine (called duplicateNumber) that checks to see if the job number exists, and if it finds that number, then it should return a true value, and the exact name of the folder. When I run the script, it cycles through the first folder correctly, but when it gets to the 2nd folder to check, it gives me an error message that says “<> doesn’t understand the duplicateNumber message”. I know that it has to do with the way the list is being sent back, but I can’t figure out why it’s wrong.
Any help would be greatly appreciated.
Brian
on run
set server_name to "XFiles" -- This is the name of the server, if the server name changes, change this variable
set server_list to list disks
set job_number to get_jobnumber()
-- folderStructure contains all the folder names that is on the server that are to be used
tell application "Finder" to set folderStructure to every folder of the folder (server_name as alias)
set dupResult to {}
if server_list contains server_name then
repeat with checkFolder in folderStructure
display dialog checkFolder as text
set dupResult to duplicateNumber(job_number, (checkFolder as text))
set duplicateNumber to item 1 of dupResult
if duplicateNumber then dupNotice(server_name & ":" & checkFolder as text, job_number, item 2 of dupResult)
end repeat
end if
end run
on get_jobnumber()
repeat
display dialog "Enter job number" default answer "" with icon note
set job_num to the text returned of the result
if (count of items in job_num) as text ≥ 4 then
if job_num ≥ 1000 and job_num < 999999 then
try
set jobnumber to job_num as number
return job_num
on error
display dialog "The job number field can only contain numbers. Please try again" buttons {"OK"} default button 1 with icon stop
end try
else
display dialog "The job number must be a positive integer below 1,000,000" buttons {"OK"} default button 1 with icon stop
end if
else
display dialog "The job number must be a 4-digit integer" buttons {"OK"} default button 1 with icon stop
end if
end repeat
end get_jobnumber
on duplicateNumber(job_num, flocation)
set itemList to list folder (flocation as alias)
repeat with foldName in itemList
if foldName contains job_num then return {true, foldName as text}
end repeat
return {false, foldName as text}
end duplicateNumber
on dupNotice(containingFolder, jobnumber, DupFolderName)
display dialog ¬
"This folder can not be created because this job number already exists in the following folder: " & return & containingFolder as text ¬
buttons {"Cancel", "Open"} default button 2 with icon note
if button returned of the result = "Open" then
tell application "Finder"
activate
open folder (DupFolderName as text) of folder (containingFolder as text)
set bounds of window of folder (DupFolderName as text) of folder (containingFolder as text) to {x1, y1, x1 + xSize, y1 + ySize}
set current view of window of folder (DupFolderName as text) of folder (containingFolder as text) to column view
select folder (jobnumber & "_ Layouts") of folder DupFolderName of folder (containingFolder as text)
end if
end tell
end if
end dupNotice