Jump to content
Server Maintenance This Week. ×

Found Set in Applescript


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

Recommended Posts

I am writing a Filemaker/Applescript solution to rename a huge number of files. Filemaker will calculate the new name, and Applescript calls a shell script to rename.

I want to be able to test on 2/3 records. The script insists on running on the whole database. I feel I should be able to say

tell found set

but I can't! Am I missing something? So many questions, but let's start with this one!

TIA.

Link to comment
Share on other sites

Do you find applescript otherwise obvious, beyond this object? I would say it's a hit and miss to get any applescript written correct in first attempt, hence the need to write the scripts in a dedicated editor before embedding. We're not showered with meaning-full error messages here!

--sd

Link to comment
Share on other sites

Not obvious, but I've been doing it a while (more scripting QuarkXPress than Filemaker though).

I just made a scary discovery - addressing 'Document' rather than 'Database' has the required effect within Filemaker. But when I took the script back out to Script Editor to get (relatively) helpful error messages, it applied the script to the whole database. Eeek. Files were being renamed and luckily I realised in time and can restore from back up.

Is this right? And if so, how do I only address the found set from within Script Editor?

Link to comment
Share on other sites

It really is most unhelpful to ask questions and make us play guessing games.

Post your script (or a simplified version) please.

In the same vein and level of detail as your question, I will state that I tried it in script editor and I do correctly get data only from the found set.

Edited by Guest
Link to comment
Share on other sites

Sorry to have caused offence! I thought the question was a fairly broad one of principle and the details of the script weren't relevant. Indeed they weren't, to the initial question. But here it is FWIW. Copying it has made me realise that the initial 'tell' still addresses the database, but I can't see that that should actually matter since all I'm doing is getting a number....

The database holds names and paths of images (19000). If it can extract a 6 digit sku code from the filename, it will rename the image with the result of a calculated field, otherwise it leaves it alone.

tell application "FileMaker Pro8.5"

tell database 1

set rec_count to count of records

end tell

end tell

repeat with i from 1 to rec_count

set do_it to "yes"

tell application "FileMaker Pro8.5"

tell document "MakroImages"

tell record i

if cell "SkuCode" ≠ "not valid sku" then

set source_file to cell "Source"

set dest_file to cell "Destination"

else

set do_it to "no"

end if

end tell

end tell

end tell

if do_it = "yes" then

set source_file to quoted form of source_file

set dest_file to quoted form of dest_file

do shell script "mv " & source_file & " " & dest_file

end if

end repeat

display dialog "Done!"

Link to comment
Share on other sites

Sorry to have caused offence! I thought the question was a fairly broad one of principle and the details of the script weren't relevant. Indeed they weren't, to the initial question. But here it is FWIW. Copying it has made me realise that the initial 'tell' still addresses the database, but I can't see that that should actually matter since all I'm doing is getting a number....

Well, you're asking for the total number of records in the database, which is exactly what you said you DON'T want to do. So I can't see how the result is a surprise.

You need to be much more specific; you need to refer to the layout.

set rec_count to (count of records of layout "YourLayoutName" of database 1 of application "FileMaker Pro8.5")

However I'd suggest you do it like this:

tell application "FileMaker Pro 8.5"

tell document "MakroImages"

set rec_count to (count of records of layout "LayoutName")

repeat with i from 1 to rec_count

tell record i

if cell "SkuCode" ≠ "not valid sku" then

set source_file to cell "Source"

set dest_file to cell "Destination"

moveFile(source_file, dest_file)

end if

end tell

end repeat

end tell

display dialog "Done!"

end tell

on moveFile(source, target)

set source_file to quoted form of source

set dest_file to quoted form of target

do shell script "mv " & source_file & " " & dest_file

end moveFile

Edited by Guest
Link to comment
Share on other sites

Thanks Bruce, that's a much more rigorous and elegant approach! There is so much to contend with in this job - not least trying to organise back up of 230gb of data, and get all those file names into the database.... And assemble the non-nameable ones into contact sheets. I'm afraid as soon as my script worked, I rather abandoned it!

I'll implement your ideas, it will be much tidier and safer. Thanks!

Link to comment
Share on other sites

This topic is 5719 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.