I’ve got a complicated script for copying movies from SD cards. I just boiled down the script to something below so I can demonstrate the issue. Basically, I want the user to tell me how many camera cards they have, then proceed with a loop for each of those camera cards. Now, my big problem is what if the user makes a mistake 5 cards into a 10 card ingest? Is there a way I can restart that instance of the loop instead of going to the next number in the count? Also, is there a way that, if the user clicks cancel, it just cancels that loop and not the whole script?
set NumberofCards to text returned of (display dialog "How Many Cards do you have?" default answer "1")
with timeout of (30 * 60) seconds
repeat with i from 1 to NumberofCards
tell application "System Events"
display dialog ("Insert card " & i & " of " & NumberofCards as text) & " into the reader."
set these_items to choose folder with prompt "SELECT YOUR CAMERA CARD!"
set showtitle to (choose from list {"Show1", "Show2", "Show3"} with prompt "What is the Show Title?")'s item 1
set shortdescription to (display dialog "Short Description")'s text returned
set dateofclip to (display dialog "Date")'s text returned
set cameraletter to (display dialog "Camera Letter and Reel Number?")'s text returned
set category to (choose from list {"_SHOOT", "_Interview"} with prompt "Category")'s item 1
set cardName to showtitle & "_" & shortdescription & "_" & dateofclip & "_" & cameraletter & category
if (count (cardName)) is greater than 59 then display dialog "ERROR: Name must be 59 characters or less" buttons {"I'll try again"} default button 1 cancel button 1
if button returned of (display dialog cardName with title "Clip Name:" buttons {"Let me try again", "Enter Myself", "Proceed"} default button 3 cancel button 1) is "Enter Myself" then set cardName to (display dialog "Enter File Name Yourself Showtitle_ShortDescription_Date_Camera_Category" default answer "Enter Here")'s text returned
set cardBackupFolder to (make new folder at (myVolume & ":VirtualAE:CardBackups" as string) with properties {name:cardName & "_CardBackup"})
duplicate these_items to cardBackupFolder
display dialog "Eject your card"
end tell
end repeat
end timeout
tell application "System Events"
display dialog "You have finished ingesting your " & NumberofCards & " cards."
end tell