KylePutzier

Searching for a specific folder using applescript (optimization help needed)

Discussion created by KylePutzier on Nov 18, 2013
Latest reply on Nov 19, 2013 by taylorsharpe

(repost to the General forum)

 

I have an applescript that works fine except it is a little slow. (see below). It basically searches for a folder whose name begins with the contents of a FMP field. If found, it displays that folder, if not found, it gives the option to create one. It ran very fast when the parent folder, being searched, was on my local machine, but I have since moved the parent folder to a network drive, which caused it to slow down.

 

Is it possible to optimize this script? I know little about applescript.

 

Kyle

 

 

note: it is a FMP calculated applescript that I have modified to make it easier to read in this post. Typos and syntax errors may have introduced during that modification. Please ignore them.

 


tell application "Finder"

set folder_names to name of every folder of folder ("/Volumes/Art" as POSIX file)

repeat with f in folder_names

if first word of f is "" & MyFile::MyField & "" then

open folder f of folder ("/Volumes/Art" as POSIX file)

activate

set Found to 1

exit repeat

else

set Found to 0

end if

end repeat

 

if Found = 0 then

set folder_names to name of every folder of folder ("/Volumes/Art/~ Completed Jobs" as POSIX file)

repeat with f in folder_names

if first word of f is "" & MyFile::MyField & "" then

open folder f of folder ("/Volumes/Art/~ Completed Jobs" as POSIX file)

activate

set Found to 1

exit repeat

else

set Found to 0

end if

end repeat

end if

 

if Found = 0 then

open folder ("/Volumes/Art" as POSIX file)

beep

set question to display dialog "The art folder for Company Item #" & MyFile::MyField &" could not be found. Would you like to create one?" buttons {"Yes", "No"} default button 2

set answer to button returned of question

 

if answer is equal to "Yes" then

set newfoldername to "" & MyFile::MyField & " " & MyFile::Graphics_FilenameSuffix & ""

set loc to ("/Volumes/Art" as POSIX file)

set newfo to make new folder at loc with properties {name:newfoldername}

make new folder at newfo with properties {name:"~ Obsolete"}

make new folder at newfo with properties {name:"~ Original Art"}

open folder newfoldername of folder ("/Volumes/Art" as POSIX file)

end if

end if

Outcomes