I’ll continue to work at this… now that there is a working base, I should be able to go back and clean it up. What is your processing speed and RAM? This works pretty fast, but I have tons of RAM.
Italiano? Provi questo collegamento:
That’s why I apologized for the translations… Colloquio a voi presto!
SC
PS: Since it works, you could run it while you sleep until we dial it in :lol:
--Get your folder
set theFolder to choose folder with prompt "Select the target Folder for name search"
tell application "Finder"
--Reference to a folder
set FolderRef to theFolder as string
--Gets contents of folder ready for processing
set TheFiles to items of folder theFolder
end tell
--Get your database file
set Database to choose file with prompt "Select the database file"
--Open the database
tell application "FileMaker Pro"
activate
end tell
tell application "Finder"
open Database
end tell
--get the name of database
set thisDatabase to displayed name of (info for Database) as string
tell application "FileMaker Pro"
go to database thisDatabase
--get field names
set IDFields to name of fields of database thisDatabase
--choose field from list
set UIFieldChoice to choose from list IDFields with prompt "Choose Field of Database '" & thisDatabase & "'"
set SelectedField to result as string
--get contents of selection
set theField to field SelectedField of database thisDatabase
--loop through records in field
repeat with ThisRecord in theField
if SelectedField is "false" then exit repeat --'Cancel button' to get out of repeat
--Get the first word of the text
set AppleScript's text item delimiters to " "
set KeyWord to first text item of ThisRecord as string
set AppleScript's text item delimiters to ""
--Search the filenames of 'theFiles in theFolder' for the KeyWord, regardless of position or case
try
repeat with CurrentFile in TheFiles
try --This deals with "filename not found" error
set CurrentFilename to displayed name of CurrentFile as string
--conditional statement finds keyword in filename
if (CurrentFilename as string) contains (KeyWord as string) then
--get the file extension
set AppleScript's text item delimiters to "."
set FileExt to last text item of CurrentFilename as string
set AppleScript's text item delimiters to ""
--Rename file to selected field text
tell application "Finder"
set name of CurrentFile to ThisRecord & "." & FileExt
end tell
exit repeat --*Now if the filename is changed, the script will stop searching and go to next record
end if
end try
end repeat
end try
end repeat
end tell
I made the change as noted above: When looking for a filname text match, if a match is found and the filename is changed, the search is exited, and the next record search begins.
SC