Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 7181 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I've searched through the archives, but haven't found something that solved my issue.

I have a number of records in a table and I am trying to use field values from each to rename files in a folder. I have written the following AppleScript. When I try to run it, AppleScript throws an error saying it cannot rename the file identified in the first record. Yet when I look at the Finder, that file has, in fact, been renamed.

Each of the records has a different value in the field for the "new name".

I wasn't positive if the variable "recordLoop" was automatically incremented, but either with or without the incrementation line, I get the same error.

Anyone have any ideas?

Thank you for your help,

Nancy

==================================

tell application "FileMaker Pro"

set myRecordCount to number of records of table "metaDataEntry" of database "metaDataEntry.fp7"

repeat with recordLoop from 1 to myRecordCount

go to record recordLoop

set newname to cell "Identifier" of table "metaDataEntry"

set filepath to (((cell "folderPath" of table "metaDataEntry") as string) & ((cell "Title" of table "metaDataEntry") as string))

tell application "Finder"

set name of document file filepath to newname

end tell

recordLoop + 1

end repeat

end tell

Posted

This line:

recordLoop + 1

is not doing anything, because you did not "set" it. So the AppleScript fails because you never left the 1st FileMaker record. But you'd renamed its file already, so the "filepath" file is no longer there; it can't rename a file that isn't there.Try:

set recordLoop to recordLoop + 1

Posted

I thought you had it solved! The problem is the script never gets to that line. shocked.gif

I tried to run the script within the "Script Debugger" demo I downloaded.

The message is:

Finder got an error: Can't set name of document file "Big Goose:Projects: theCumulator:metadataEntryProgram:filesToProcess:05_0310 discussion.doc" to "20050324125539.doc".

The "Offending Object" is:

name of document file "Big Goose:Projects: theCumulator:metadataEntryProgram:filesToProcess:05_0310 discussion.doc"

The "Expected Type" is:

"20050324125539.doc"

The AppleScript error number is "-10006"

I DO need to supply the complete path to the file in "set the name" script line, right? Does this have something to do with aliases or something?

=====================================

tell application "FileMaker Pro"

set myRecordCount to number of records of table "metaDataEntry" of database "metaDataEntry.fp7"

repeat with recordLoop from 1 to myRecordCount

go to record recordLoop

set newname to cell "Identifier" of table "metaDataEntry"

set filepath to cell "folderPath" of table "metaDataEntry"

set oldName to (filepath & (cell "Title" of table "metaDataEntry"))

tell application "Finder"

set the name of oldName to newname

end tell

set recordLoop to recordLoop + 1

end repeat

end tell

=====================================

Thank you so much for your help,

Nancy

Posted

Try this:

set filepath to cell "folderPath" of table "metaDataEntry"

set oldName to (filepath & (cell "Title" of table "metaDataEntry")) <-- text result

tell application "Finder"

set the name of oldName to newname <-- You're referencing text, not a file

-- this should be

set the name of file oldName to newname

Posted

Same results. frown.gif

I checked the value of 'recordLoop' to make sure it was 1, just to make sure the loop actually hadn't gone around once.

Once again, the file DOES actually get renamed, yet the script says it can't. confused.gif

How can I make sure the Finder thinks what I am handing it is a reference to a file, not just a string of text?

Thanks for the continued help,

Nancy

========================================

tell application "FileMaker Pro"

set myRecordCount to number of records of table "metaDataEntry" of database "metaDataEntry.fp7"

repeat with recordLoop from 1 to myRecordCount

go to record recordLoop

set newname to cell "Identifier" of table "metaDataEntry"

set filepath to cell "folderPath" of table "metaDataEntry"

set oldName to (filepath & (cell "Title" of table "metaDataEntry"))

tell application "Finder"

set the name of file oldName to newname

end tell

set recordLoop to recordLoop + 1

end repeat

end tell

========================================

Posted

OK, I tried your code (minus the renaming part, because that isn't the problem). If you run the code with that part commented out, you'll see that it is the way you're referencing the cells which is the problem. I did this in Script Editor, in the Event Log pane.

Basically it's always using the 1st record. You're going to each record, but the cell reference still gets the 1st; because you haven't told it you want the current record. AppleScript can get a value from any record, no matter where it happens to be. In FileMaker you only have access to the current record (unless you use a relationship), so that is implied.

There are 3 ways to address a database with AppleScript. "database" means "the entire file", whereas "document" or "window" reference the found set. It matters because you're running a loop. If you have a found set your loop will get an error at the end, 'cause the count of the database is greater than the found set.

If you're going to use the name of the database, then:

document "name" is fine (".fp7" is optional)

If you're on the correct layout already, then "window 1" will do. Be wary of "document 1", it doesn't mean the top window; it's the first one opened that session.

Much the same with "table" and "layout." If I have 2 records (of 3) showing, and I count records of the table, I get 3; whereas count records of layout is 2.

I think this structure will work:

tell application "FileMaker Pro"

Posted

YES!!!!

Except for your small, itty bitty boo-boo of setting 'oldName' to "filepath & newname"....... it worked fabulously!

THANK YOU from the bottom of my toes. smile.gif

Nancy

Posted

I "fixed" my boo-boo. You confused me by setting "filepath" to cell "folderPath". I usually name my variables much the same as the FileMaker cells. Keeps me from making this kind of mistake.

This topic is 7181 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.