On error select file

Hello, I have managed to make a nifty script that will pull data from FMP and them move the files located in the data to a new folder (Pre-Press environment) I have posted to the BBS twice and received great help. Now I would like to manage any errors that may show up. If a file that is listed in the data is missing I would like to have the user have an option to find the file and then continue or just continue. Is this possible. Below is the error that is in a try statement. Also I marked where the script gets hung up. If you want the whole script I will be glad to share. Thanks in advance.

repeat with i from 1 to the_number_of_records
with timeout of 10 seconds
try
on error
set result to {myversion, formnum} --problem is here
display dialog "Cannot find file" & myversion & "from form number" & formnum & "." buttons {"Continue", "Find It!"} default button "Find It"
set button_name to button returned
if button_name is "Continue" then
continue i from 1 to the_number_of_records --how do i continue with script?
else if button_name is "Find It!" then
set missfile to choose file with prompt "Choose file to move to Form Number" & formnum
tell application "Finder"
select file missfile
move selection to folder formnum in folder myvendor in disk "Apps"
end tell
end if
end try

OK after some persistance and 6 hours in front of my scree i hae the first two fixed. I still need help with the continue button though. Anyone know how to do this. See last post for script.

I don’t usually use applescript for user interactions. My advice: don’t ask the user to locate the file each time the move command fails, instead when a file isn’t located (that is, the “move” fails), write the name of the missing file to another file. When all the processing is done, show the list of failures to the user, then let the user decide what to do about the missing files. Now why: if the list of files to be moved is long enough, the user must sit at the computer waiting for it to present the “file not found” dialog box. (Adding “giving up after” to the dialog command will slow things down.)

But if you want to ask the user about every failure when it happens… your task is more difficult than you think (with plain applescript). You’ll need a “try… on error” block everywhere the user might click the “cancel” button (for example, in the file selection dialog box).

Also there is this:

make new folder in disk "Apps"
select folder "untitled folder" in disk "Apps"
set name of selection to myvendor
select folder myvendor in disk "Apps"
select folder myvendor in disk "Apps"
make new folder in folder myvendor in disk "Apps"
select folder "untitled folder" in folder myvendor in disk "Apps"
set name of selection to formnum

will work better if you use

set myvendor to "test vendor name"
set myform "to test form name"
tell application "Finder" to set vendor_folder to make new folder at disk "Apps" with properties {name:myvendor}
vendor_folder  -- returns  folder "testvendorname" of disk "Apps" of application "Finder"
tell app "Finder" to set form_folder to make new folder at vendor_folder with properties {name:myform}

There is no need to select an item prior to moving. Simply instruction the Finder to move it. If the user accidently clicks the mouse, the selection is lost and your script is lost, too.

It’s difficult for me to understand exactly what you want, so if the following doesn’t make sense, forgive me. Note also this is psuedocode, not applescript. It’s only for structure

set file_list to list of files that need to be moved
repeat with one_file in file_list
  try
    move file from wrong_location to right_location
  on error
    display dialog "file missing" & name of file with buttons "hunt for it" "forget it"
    if button is hunt for it then
      try
        choose file
        set wrong_location to chosen file
        move file from wrong_location to right_location
      on error --user canceled
        do something or not, depending on what you need
      end try
    end if
    -- if selection is "forget it", the repeat loop will continue with the next item
    -- if the selection is "hunt for it" the repeat loop will continue with the next item
    -- regardless of whether the user found the file, couldn't find the file, or cancelled
  end try
end repeat

Thanks again Andreas

I found the correct location where I want it to tell me if there is an error, now the display does not show when there is an error. It seems to skip over it and finish the script. Here is the lines i have in relationship of the where I want the error to display. 1-Location I put try statement if the file is not found I want an error displayed 2- the display I would like to show 3- how can I continue the script if user presses the “continue” button?

tell application "Finder"
make new folder in disk "Apps"
select folder "untitled folder" in disk "Apps"
set name of selection to myvendor
select folder myvendor in disk "Apps"
make new folder in folder myvendor in disk "Apps"
select folder "untitled folder" in folder myvendor in disk "Apps"
set name of selection to formnum
try --1
select file myversion in folder "Test Files" in disk "Apps" --find file and moves it
on error
display dialog "Cannot find file: " & myversion & " from form number: " & formnum & "." buttons {"Continue", "Find It!"} default button "Find It" --2
set button_name to button returned
if button_name is "Continue" then --3
continue i from 1 to the_number_of_records
else if button_name is "Find It!" then
set missfile to choose file with prompt "Choose file to move to Form Number" & formnum
tell application "Finder"
select file missfile
move selection to folder formnum in folder myvendor in disk "Apps"
end tell
end if
end try
move selection to folder formnum in folder myvendor in disk "Apps"
end tell

Thanks for the advice, but when i work in all my variables, it breaks the calls to the created folders later on in the script. Since I’m a newbie, it looks like I’m back at square one with the change unless its an easy fix.

This script was a simple hands off until an error sort but as for the list it sounds good.

The idea of having the user choose the file would be nice. The file could be reuploaded to our server then the user could choose it. But I can see the good of the list if it listed what form # the file would belong to. I have the “Choose missing file” part finished and it seems to work well. Like mentioned before I’m new and I would need to explore your psuedocode to see if i could get my variables into it.

If anyone finds this script useful or interesting please feel free to download the builds from my iDisk here.

http://homepage.mac.com/marcinkevics/FileSharing11.html

At 1 is my problem. the script can’t find the folder to move the file to. Its probably looking me in the face.

tell application "FileMaker Pro"
show every record in document 1
sort document 1 by field "Form Num" in order ascending
set the_number_of_records to the count of records in document 1
set myvendor to cell "Print Vendor" of current record in document 1
set formnum to cell "form num" of current record in document 1
set mypdf to ".pdf" --
set myversion to cell "version info" of current record in document 1
set myversion to myversion & mypdf
--set myvendor to "test vendor name"
--set formnum to "test form name"
tell application "Finder" to set myvendor to make new folder at disk "Apps" with properties {name:myvendor}
myvendor -- returns folder "testvendorname" of disk "Apps" of application "Finder"
tell application "Finder" to set form_folder to make new folder at myvendor with properties {name:formnum}
--formnum end tell tell application "Finder"
try --1
select file myversion in folder "Test Files" in disk "Apps" --find file and moves it
on error
beep 3
set file_error to display dialog "Cannot find file: " & myversion & " from form number: " & formnum buttons {"Continue", "Find It!"} --default button "Find It" --2
set button_name to button returned of file_error
if button_name is "Continue" then --3
continue i from 1 to the_number_of_records
else if button_name is "Find It!" then
set missfile to choose file with prompt "Choose file to move to Form Number" & formnum
tell application "Finder"
select file missfile
move selection to folder formnum in folder myvendor in disk "Apps"
end tell
end if
end try
move selection to folder myvendor in folder formnum in disk "Apps" --1 heres the problem
end tell