views:

48

answers:

2

OK I have one that doesn't seem to be answered. I'll past the whole script

The problem is with the TRY. Since it is happening in the Finder and I am trying to pass some info back to FM. THis works fine as a FM script but fails in the runtime. As far as I can tell the only solution would be to change all the Filemaker Pro Advanced references to the runtime app BUT I can't do that because FMPA wants me to show it the app and of course it isn't built yet! So I guess I could build the runtime and then edit IT'S scripts to work. But that seems like a funky workaround. I tried using "me" but I think because it's part of a try still running in the Finder it fails.

-- script to copy files to PT directory 1/21/02

set copysounds to ""  
set thetarget to ""  
set x to ""  
set filename to ""  
tell application "FileMaker Pro Advanced"  
--activate  
 set recordCount to count of records  
end tell  
choose folder with prompt "Pick a destination folder"  
set thetarget to result  
repeat with x from 1 to recordCount  
tell application "FileMaker Pro Advanced"  
  set copysounds to cell "Find Path" of record x  
  set effectName to cell "Effect Name:" of record x  
  set filename to ((thetarget as text) & (cell "Effect Name:" of record x))  
  set cell "error flag" of record x to ""  
  set notFoundError to ""  
  set DupOK to ""  
  -- find out if file esists  
  tell application "Finder"  
   activate  
   try  
    alias copysounds  
   on error  
    set notFoundError to "true"  
    display dialog effectName & "  file was not found.  Check     Path." buttons {"OK"} default button 1 with icon stop  
   tell application "FileMaker Pro Advanced"  
     set cell "error flag" of record x to "Path Invalid"  
    end tell  
    --return  
   end try  
+1  A: 

Not having a copy of the database makes it hard for me to test but lets start here. You have allot of things out of place so I fixed up your code

try this

  -- script to copy files to PT directory 1/21/02

  set copysounds to ""
  set thetarget to ""
  set x to ""
  set filename to ""
  set thetarget to choose folder with prompt "Pick a destination folder"
  tell application "FileMaker Pro 10"
    set recordCount to count of records
    repeat with x from 1 to recordCount
        set copysounds to cell "Find Path" of record x
        set effectName to cell "Effect Name:" of record x
        set filename to ((thetarget as text) & (cell "Effect Name:" of record x))
        set cell "error flag" of record x to ""
        set notFoundError to ""
        set DupOK to ""
        try
            tell application "Finder" to alias copysounds
        on error
            set notFoundError to "true"
            display dialog effectName & "  file was not found.  Check     Path." buttons {"OK"} default button 1 with icon stop
            set cell "error flag" of record x to "Path Invalid"
        end try
    end repeat
  end tell
mcgrailm
also it just noticed that your currently only checking the the "find path" location I'm assuming your taking it step by step. can I see the results of for copyysounds I would like to know what that looks like
mcgrailm
I probably should have added some general notes. The database is a catalog of sounds used in film etc. You can add to the catalog and do searches and tag files you want to use. This script is for copying the files from the place they live (usually a library drive) to a user specified folder. The "Find Path" is just the full path to the file.
ScottK
THe code is probably a bit klunky since this was an early project that I am dusting off and trying to update and when originally done it was the first time I used Apple scripts much. I'm not sure if some of this was how it used to work? or just over kill on my part back when. I do remember having to add tell's in to get back to FMP, but again I was very new to this then so it might just have been something silly. Now it's been a long time and I'm sort of "new to it all over". Anyway the script works fine as long as I'm running it in FMPA. It's creating a runtime that is the problem.
ScottK
Thanks for the clean up and that is on the ToDo list but I wanted to get it working before I started working on the optimizing part. Though they may be hand in hand? I'll try your code but I don't think it will solve my basic problem and that is that the run time can't reference "FileMaker anything", it wants to reference the compiled app. I can probably find a kludgy way around it but how is one supposed to debug is you can't run the code in the development environment?
ScottK
I wasn't trying to knock your code just want to try to clean it up as starting point. we all need to start somewhere I put my code in and out of FMP and it worked in both places. I created a db with a single field with a name of "Find Path" and put in a path in a record like this "Macintosh HD:Users:username:Desktop:folder"maybe i'm misunderstanding the problem ?
mcgrailm
Don't worry I wasn't being defensive. The code evolved of a lot of trial and error and once it all worked I never went back and did a real clean up. Plus I appreciate the cleaned up version, it's very useful to me as a learning tool so thank you.
ScottK
The problem is that in the code I have the Finder test to see if the file exists and then set a field in the FM db. Since the call to FM is inside of the Finder's TRY I need to tell Applescript that the SET is a command for FM. If I don't I get an error because SET isn't a valid command for the Finder. BUT when FM makes a runtime it changes the name of the "application" so a call TO FM will fail. That is what I'm trying to work around.
ScottK
ok and did you try my code ?
mcgrailm
does "effect Name" have a semicolon in field name in FMP ?
mcgrailm
Yes and Yes. And with a slight modification (I commented out the FMP10 call) it WORKED! I thought it would have the same problem, and I'm pretty sure it would have with the FMP call, but it works with out the explicit call so all's good. I think it's because by calling the Finder for the specifics it's returning focus back to FM instead of leaving it in the Finder? I actually need to get back to some sound editing but I will really look at it tonight. Since this seems to be a MUCH better approach than I was using I should rewrite the other scripts also. It seems a lot cleaner.Thanks
ScottK
yeah you use a different version of fmp so if your original call of "FileMaker Pro Advanced" in place of my "FileMaker Pro 10" it should work and you will be able to take it in and out of filemaker no problem I think your original problem was that you where not opening and closing calls properly
mcgrailm
But I'm glad you got it working
mcgrailm
I plowed through the rest of the scripts and got them all happy. I actually eliminated all the calls to FMP. I'm not sure if the way I did it was how it used to be done or if it was always a bit wanky but the new scripts are much cleaner and they work in the runtime so I can send some betas out.If you drop me a line with your name I'll add you into the thanks on the info page. It may have been a small thing but it had me totally [email protected]
ScottK
A: 

UPDATE: Pardon a simple question, but do you have the database open when you run the script as an application or otherwise. The only way I can get the same "object not found" error in Applescript is if I don't have database open. See the following example...

tell application "FileMaker Pro"
    set theRecords to records --> if a database isn't open in Filemaker, this gets an "object not found" error.
    return theRecords --> if a database is open, a list of records is returned.

end tell

I can't help but think that something more fundamental than runtimes is being missed here.


As far as I can tell the only solution would be to change all the Filemaker Pro Advanced references to the runtime app BUT I can't do that because FMPA wants me to show it the app and of course it isn't built yet! So I guess I could build the runtime and then edit IT'S scripts to work. But that seems like a funky workaround.

You can save the script as an application and save it so that you can edit it in the Script Editor application. I've done this numerous times before. For debugging, instead of going to the activity viewer, you can write to a file instead and read that when the script is done doing its thing. It's funky but not out of the ordinary for Applescript.

I tried using "me" but I think because it's part of a try still running in the Finder it fails.

mcgrailm's code is much cleaner, but it seems to me you're still going to get an error on the try regardless if you use me or not; trying to get the alias of a file will return an error if the path is incorrect every single time. If the error is here...

 try
    tell application "Finder" to alias copysounds
 on error

...then you need to investigate the value copysounds and how that value is generated. I agree with mcgrailm that sample data from your FM DB would be really helpful here, and so would the exact errors you are getting from the try. Something like this will help capture that...

try
    -- insert actions here
on error the error_message number the error_number
    -- do something with the strings error_message and error_number
end try
Philip Regan
I'll put in the error capture, should be there anyway. The error I get is "object not found" It's the same error I got when I first ported the DB and the scripts were referring to FMP and I was now running it on FMPA. I could be wrong but I think it is just because the reference has to be the DB and that is not FMPA in a runtime. My guess is that I need to break it up into separate scripts so I can use the ME reference but out side of the Finder's try function.It just seems stupid to me that FMP can't translate self references as part of the compile.
ScottK
Oh and the reason for the error check is that people move sounds around in the library all the time. You just can't stop people from "tiding " things up. So I check to make sure that the file they want to copy is still in the same location. There is a whole separate section for catalog maintenance and reconnecting records to valid paths. I need to go through all the scripts and eliminate any hard references to FMP. This may be the only script where I have this problem so that wouldn't be so awful if I have to do a weird dance to hand off the error back to the DB.
ScottK
If people have permission to touch the actual files and move them around but their locations are crucial to your systems' operations, then I suggest you invest in some kind digital asset management system to prevent people from moving the files.
Philip Regan
This is the digital asset management system. Quickie background. In film postproduction the sound editors have a library of thousands of sounds. Traditionally they used to use paper lists and then disk cataloging software. But then you still had to find the file, play it to see if you really wanted it. And then copy it to a "work" drive to use it. This db catalogs libraries of sounds so you can search them, lets you play them from the catalog and "tag" the ones you want. Then you click the copy button and all of the tagged files are copied to a folder you specify.
ScottK
The library is very dynamic. It changes all the time. Usually this is just additions but sometimes folks correct spelling or change a name or move a file. That is going to happen and any app that doesn't let it happen is useless in this workflow. And it doesn't break anything. I check that the file exists if not it's flagged and there is a way to reconnect it.Other than code clean up all of this works perfectly until I make a runtime. Then the references get broken because FM changes the name of the "application". I'm just surprised that there isn't built in way to solve this.
ScottK
@ScottK: "The library is very dynamic. It changes all the time. Usually this is just additions but sometimes folks correct spelling or change a name or move a file. That is going to happen and any app that doesn't let it happen is useless in this workflow. And it doesn't break anything." But, clearly, things are being broken if you can't sort out the simple path to a file. This is neither Filemaker nor the Finder's problem to solve; this is purely human error, for lack of a better term. There are systems designed to allow changes to be made to happen without breaking workflows.
Philip Regan
I would highly suggest looking into digital asset management systems because that will resolve all of this you trying to fix with tools that weren't designed to do so. I currently manage 3,000+ books of data spread across 500k files that amounts to 4+ TB of data at the publishing company I work for. We add to and alter that collection every day and nothing breaks. I can tell you from personal experience that you have gone beyond Applescript, Filemaker, and the Finder for your content management needs. Contact me via my profile and I would be happy to point you in a few directions.
Philip Regan
The error is that the script is trying to get FM to do something BUT once you make a runtime you are not running "Filemaker anymore" so the call generates an error. It does find the file there is no issue with that the error is because when running in FM you need to tell the script that your making the call TO FM because it's in the middle of a TRY that is pointed at the Finder. It has nothing to do with the path you could do anything in that loop that put a call to FM and get the same error.
ScottK
I use a specialized tool to manage my library, it runs around $1K. My library is currently at around 750,000 files. This is a tool for people with much simpler needs and can't justify that kind of expense.As I keep pointing out the script runs fine. It's the RUNTIME that breaks the connection.Maybe I just need to re-ask what I think is the real question. How do you write a script that references FM and keep the reference valid in runtimes.
ScottK
I think there is something else going in your setup that is interfering with the script. The only way I was able to get the "object not found" error was when I ran anything and a database wasn't open. As to the question "How do you write a script that references FM and keep the reference valid in runtimes." You don't. You go find a tool that is better suited to managing 750k files in a dynamic library scenario. Time is money and if you're spending time fixing someone else's file issues, then that's time away from doing those things that make money. But, that's your call in the end. Good luck.
Philip Regan
Thanks for the responses. I don't think you read my last post. I am using a quite pricey application to manage my library. I anybody is working at that level I would recommend the same pricey app. This FM app is for much smaller libraries and simpler needs. THe answer turned out to be using onetime finder calls so that the focus didn't stay with the Finder. Some how I write A and you read B? I am not fixing other peoples file issues. If you want to dup my problem write a script that makes a hard call to FMP. Make a runtime and call the script.
ScottK
Not everyone can be David Foster Wallace, but it was easy to misread your description of your workflow. While I think it's great you were able to get your script working again (and moving some of that code into subroutines would help with managing `tell` statements), I still think you can do better in terms of workflow. I was, at one point, literally in the same situation you are now—lots of files in a dynamic library requiring external access—and DAM resolved all of the issues that you are writing scripts for now. But, again, it's your work environment, and your call. Cheers
Philip Regan
not sure who DFW is but it is certainly as likely or more so that I was unclear. I appreciate the help.CheersSK
ScottK