hi, please some one have the power to help me?!??!!
i’m getting insane in trying to
get field content as text of a record in filemaker 6.0 and rename a file (whose the first word is the same of the above specified field ) in a foder that i can select.
many thxs,dave
Go to the FM application folder and check out the Sub-Folder “FileMaker and Apple Events”. Within there you can find tons of examples along with documentation.
It should help you with this problem and many more!
I need a little clarity on what your trying to do:
That we can do
This part needs clarification.
Rename a file-
Will you find the folder it is in, and name it to the first word of the field, or
The file has this name already and you want to rename it?
Or I totally missed it?
SC
you’right, the file has this name already and i want to rename it!
to be totally clear the applescript should work like this:
i click a button, the apllescript let me choose the folder in wich to look for the file,
go to the first record and get the field content as a text string, (4example: “cat is on the table”),
look in the folder that i’ve specified and find the file whose filename already start with the first word “cat” and rename it,
go to next record and do the same untill the last record.
i click a button, the apllescript let me choose the folder in wich to look for the file,
*You want to choose a folder, and open the folder so you can manually select and open the database with the record? Below you say you specified a folder, so I assume your not trying to (choose file).
go to the first record and get the field content as a text string, (4example: “cat is on the table”),
look in the folder that i’ve specified and find the file whose filename already start with the first word “cat” and rename it
*Script would then search the folder you specified for an existing filename with the field data? What would the file be renamed to? Do you want a prompt to come up to rename the file manually?
*go to next record and do the same untill the last record.
No prob
You can’t settle for posting only what makes sense to you. It must be organized so that each variable’s purpose in your script is defined. Love to help.
SC
This does for me what you described-
*I choose a folder containing files.
*I choose the file that contains the records (database file)-This can be eliminated if the file is always in the same location
*The script gets the string from a record in the database, gets the first word of the string, and compares that word against the filenames in the folder I chose.
*If the word is in a filename, a prompt comes up to rename it.
I figured if I give you this you can tell me what’s not ‘what you had in mind’
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
set Database to choose file with prompt "Select the database file"
tell application "FileMaker Pro"
activate
end tell
tell application "Finder"
open Database
end tell
set thisDatabase to displayed name of (info for Database) as string
tell application "FileMaker Pro"
go to database thisDatabase
set counter to 1 as number
try --Go through records in thisDatabase
repeat with i in thisDatabase
--Set theString to the record you are in
set ThisString to ((record counter) of database thisDatabase) as string
--Set Keyword to the first word of theString
set AppleScript's text item delimiters to " "
set KeyWord to first text item of ThisString as string
set AppleScript's text item delimiters to ""
--Search theFiles in theFolder for the KeyWord, regardless of position or case
repeat with CurrentFile in TheFiles
if (CurrentFile as string) contains (KeyWord as string) then
display dialog "Rename the File " & CurrentFile default answer ""
--Get new name
set NameHeader to text returned of result
--rename file
tell application "Finder"
set name of CurrentFile to NameHeader
end tell
end if
end repeat
set counter to counter + 1
end repeat
end try
end tell
thx CS,
appreciate ur usefull help, u’re making me clarify many things,
and i’ve to apologise for my unclearity,
…i’ll try to do my best with my poor english this time in describing everithing:
i’ve already opened in Filemaker 6.0 my database and i click a button from the inside of the database,
it executes a script that i’m trying to define in SciptMaker,
this script shoud perform an applescript (if necessary) that do mainly these steps:
let me choose the folder in wich to look for the files whose i want automatically modify the names ;
go to first record of my database ;
set X as text to the the content of a field called Y ;
looking in the folder i’ve specified and if the first word before space of X is = first word of the filename before space
automatically rename the file to X
open this file (is an image in jpg format) in Photoshop7 or Photoshop CS and make a 1 cm whyte line at the bottom of this image with the X text write on it (possibly aligned orizzontally left and vertically centered, respect the white line)
flatten the image
save and close the mdified image (i dont’ need to keep the original image)
go to next record of my database and do the same untill the last record
hope , this time my technicall english is’nt too much “acrobatic”,
thxs,dave
We are a bit like these computers, if we don’t get the language, we can’t do the task. I must say I still don’t quite get it, and the addition of the Photoshop task would rule me out of helping, since I don’t have that program. My advice is to study AS since this requires two programs that a user must have to make this work, and is a very specific task.
SC
…i’ll follow ur advice and starting to study AS,
but excluding the Photoshop task can you still help me with the applescript that rename a file,… 4example modifing the one you sent me?
*I choose a folder containing files.
*I choose the file that contains the records (database file)-This can be eliminated if the file is always in the same location
*I choose a field of this database in wich to look for the text
*The script gets the text from that field of the first record in the database, gets the first word of that field, and compares that word against the filenames in the folder I chose.
*If the word is in a filename, it will automatically rename the file with the text of the field in wich we’are looking, otherwise go to the next record and do the same.
*go to next record and do the same untill the last record
I can assist, however you have again added another variable: field of the record. You may have expressed this earlier, but I’m getting a clearer picture. I think we can get you to the photoshop actions point, but I have a question. Why are you using Filemaker as a database? Is that necessary?
SC
Depending on the complexity of the data, you might use the script to hold the data.
You could have a prompt come up with a list that comes up with the possible text (text that was in the field you selected). Choose the text and the rest of your script executes.
You could build this list, erase it, modify it, whatever. I’m sure you can understand my questioning, as I haven’t seen the database (each one is custom!) and its a bit like feeling around in the dark. I need to be sure since your new to this that there isn’t a more efficient way of doing this.
SC
As I’m questioning all this, I’m still working on what you requested becuase it’s pretty much there.
--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
--ID's the record by number
set Reccounter to 1 as number
--Gets the record contents
set TheRecords to records of database thisDatabase
--set up a loop to move through records
repeat with ThisRecord in TheRecords
--Prompt to choose "field" of record by listing field items
set UI to choose from list ThisRecord with prompt "Select The Renaming Text From Record " & Reccounter
--Text of the field you selected
set selectedText to result as string
if selectedText 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 selectedText 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
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 selectedText & "." & FileExt
end tell
end if
end repeat
end try
set Reccounter to Reccounter + 1
end repeat
end tell
to be honest, i feel lucky for your precious help,
but it’s still not perfect cause i should select the name of the field only one time in wich to automatically look for the text (is always the same field of every record that already contains the text that i want)
we could see things like this:
*I choose a folder containing files.
*I choose the file that contains the records (database file)-This can be eliminated if the file is always in the same location
*I choose the name of the field of this database in wich to look for the text
-LOOPS START
*The script gets the text from that field of the first record in the database, gets the first word of that field, and compares that word against the filenames in the folder I chose.
*If the word is in a filename, it will automatically rename the file with the text of the field in wich we’are looking, otherwise go to the next record and do the same.
*go to next record and do the same untill the last record
-LOOPS END
I knew it was getting close. Everything from here is manipulating the script we already have. So there are a couple of refinements and considerations.
*Will the filenames to be changed always have the format ‘w.xyz’
1.jpg
23.tif
picture143.gif
are all acceptable because of the way the new filenames are assembled in the script. I strip “.xyz” (parse is the true term) from the filename, and then add it back to the field text you selected. If there is no file extension, or if there is more than one “.” in the filename, you will end up with names like “big black cat.big”, etc.
*If the word is in a filename, it will automatically rename the file with the text of the field
Very specific-> Here you’re saying “if the word is in a filename at all”. That includes cases like
search: dog - filename: The Big Dog.jpg → would be true
but in an earlier post you said
“if the first word before space of replacement text is = first word of the filename before space”
Which sounds like a condition that the search keyword has to be the first word in the existing filename.
Does renaming happen if the keyword is anywhere in the existing filename, or only if it is the first word?
This should satisfy the last post-
Search and rename, selecting the field choice only once:
--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
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
end if
end repeat
end try
end repeat
end tell
I forgot to suggest testing this on a small group of files before using it, of course. This should work for you, works for me.
SC
…let’s say my file’s name are:
01.jpg
02.jpg
03.jpg
let’s say the field in wich we are looking of my database contains this words:
01 video ok (first record)
02 video ok (second record)
03 video ok (third record)
i play the script and it change only the first filename every time i play it, so that i have to run 3 time the script to change 3 files names…
so after the first time i play the script i have this filenames:
01 video ok.jpg
02.jpg
03.jpg
so after the second time i play the script i have this filenames:
01 video ok.jpg
02 video ok .jpg
03.jpg
and after the third time i play the script i have this filenames:
01 video ok.jpg
02 video ok .jpg
03 video ok .jpg
Molto buon! I was able to recreate and track down the error…
The script works by grabbing a record, searching through filenames and changing them. Problem was, when you got to the next record, the filenames were searched through again. *The finder had not yet indexed the changed filename from the first round, so it could not make that filename into a string, and quit the script. This was fixed by telling the finder to skip a filename if it couldn’t access the displayed name. Its ok to skip these names because they’ve already been processed. Let me know how this works, as always…
--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
end if
end try
end repeat
end try
end repeat
end tell
hi,
…it work but really slow…
it took about 1 hour to work with a database of 100 record, and with a folder than contains 100 images…
so like this the script is useless and unusable, considering that my database has got 3000 record and the folder something near 2900 files…
Can we try to improve the performance of the script considering that:
as soon as a filename is changed, there is no need to scan through the other files of the folder because every record has got only one correspondent file in the folder
(even if not every record has got his correspondent file) ,
so the script could stop scannig through the other files, go back to filemaker an go to the next record and do the same operation again
when a filename has been changed, there is no need to scan this file again ,
so for example it could be move in a temporary folder and put it back in the original folder and the end of the process, or something else that do same function…so that hypothetically when the script scan the last record of the database has only one file to scan in the folder…
3)the situation is something similar to this:
Database records ordered | folder ordered by flilenames ascending
ascending by the field considered |
|
|
record 1: 0001 abc ok | first file: 0001.jpg
record 2: 0002 xyz no | second file: 0002.jpg
record 3: 0003 franck yes | third file: 0003.jpg
…
record 3000: 3000 mark wxh | file 2981: 3000.jpg
there is not a perfect correspondance between records and filenames(position) so ordered , because some image miss,
but this to say that, if the script start from the first record of the database and start to scan the files from the first one, both alphabetically ordered, and there is no need to scan the files already changed, there is a good chance to find the correspondent file immidiatly.