I’m getting stumped trying to sort out a problem with the following script. I’m building a list of all of the map files (in eps format) in a particular set of subfolders. I’m taking that list and I’m trying to identify one map in particular, and then grab that reference for later use. I’m trying to identify the particular map by file name. However, I’m getting an error when using “whose” in the following way:
property mapString : "abc.eps"
tell application "Finder"
set searchFolder to choose folder
set subFolders to folders of searchFolder
set mapList to {}
repeat with thisFolder in subFolders
set mapList to mapList & document files of thisFolder
end repeat
set thisMap to (items whose name is mapString) of mapList
end tell
property mapString : ".scpt"
set mapList to {}
set searchFolder to choose folder
tell application "Finder" to set allFiles to files of entire contents of searchFolder
-- entire contents drills down through all folders
repeat with aFile in allFiles
if name of contents of aFile contains mapString then set end of mapList to contents of aFile as alias
-- or you can do whatever to the file itself
end repeat
I don’t know why its not working, but I go this to work…
property mapString : "abc.eps"
tell application "Finder"
set searchFolder to choose folder
set subFolders to folders of searchFolder
set mapList to {}
repeat with thisFolder in subFolders
set mapList to mapList & document files of thisFolder
end repeat
set thisMap to {}
repeat with aMap in mapList
if name of aMap is mapString then set end of thisMap to aMap as string
end repeat
end tell
What you seem to be looking for is something like this:
property mapString : "abc.eps" as Unicode text
set searchFolder to (choose folder)
try
tell application "Finder"
set thisMap to (first file of entire contents of searchFolder whose name is mapString) as alias
end tell
on error
display dialog "File "" & mapString & "" not found in this hierarchy."
error number -128
end try
However, if you have a lot of subfolders and/or files, you might find it rather slow. The following method happens to be much faster, for no particularly good reason:
property mapString : "abc.eps" as Unicode text
set searchFolder to (choose folder)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
tell application "Finder"
set entireContents to (files of entire contents of searchFolder) as Unicode text
end tell
set AppleScript's text item delimiters to ":" & mapString & return
if ((count entireContents each text item) > 1) then
set thisMap to (get paragraph -1 of text item 1 of entireContents & ":" & "abc.eps") as alias
else
display dialog "File "" & mapString & "" not found in this hierarchy."
error number -128
end if
set AppleScript's text item delimiters to astid
thisMap