• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How do I avoid a Repeat loop to abort upon errors?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I avoid a Repeat loop to abort upon errors?


  • Subject: Re: How do I avoid a Repeat loop to abort upon errors?
  • From: Jim Skibbie <email@hidden>
  • Date: Sun, 25 Oct 2009 19:59:53 -0500
  • Thread-topic: How do I avoid a Repeat loop to abort upon errors?

Title: Re: How do I avoid a Repeat loop to abort upon errors?
Insert a ‘try block’ where you want to trap the error, then use the “on error” to tell your script what to do when the error happens. I’ve included a handler that allows you to write to a file as an example, but you can do anything you want with the error. I have not tested this, but it should be what you’re looking for.

Thanks.
Jim

set logFileName to "This is the name of my log file.log"
set
logFile to (((path to desktop from user domain) as text) & logFileName) as text -- this is the path to the log file (right now the desktop), but you can change the path to wherever


tell application "iPhoto"
   repeat with i from 1 to the count of these_images
       set the keywordslist to ""
       set this_photo to item i of these_images
       tell this_photo
           set the image_file to the image path
           set the image_title to the title
           set the image_filename to the image filename
           set the image_comment to the comment
           set the assigned_keywords to the name of keywords
       end tell
       repeat with j from 1 to the count of assigned_keywords
           set the keywordslist to keywordslist & " -keywords='" & item j of assigned_keywords & "'"
       end repeat
       -- insert the try block to trap the error
       try
           set output to do shell script ¬
               "exiftool -title=\"" & image_title & ¬
               "\"" & keywordslist & ¬
               " " & " -Caption-Abstract=\"" & image_comment & ¬
               "\"" & " -Copyright='" & copyright & ¬
               "' " & " -CopyrightNotice='" & copyright & ¬
               "' " & " -Rights='" & copyright & ¬
               "' " & " -Marked='" & Copyrighted & ¬
               "' " & "\"" & image_file & "\""
           do shell script "rm \"" & image_file & "\"" & exifToolOriginal
       on error errMsg number errNum
           -- if an error occurs, you can write a line out to a log file using this DebuggingLog handler
           set logFileErrorString to "The following error occurred: " & errMsg & " Error No: " & errNum & return
           try
               my DebuggingLog(logFile, logFileErrorString)
           on error errMsg number errNum
               display dialog "An error occurred writing to the log file: " & errMsg & " No: " & errNum
           end try
       end try
   end repeat
end
tell

on DebuggingLog(outFile, myData)
   try
       set fileRef to (open for access outFile with write permission)
       write (myData) to fileRef starting at eof
       close access fileRef
   on error errMsg number the errNum
       try
           close access outFile
           error errMsg number errNum
       end try
   end try
end
DebuggingLog
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: How do I avoid a Repeat loop to abort upon errors?
      • From: AndrĂ© Sartori <email@hidden>
  • Prev by Date: Re: Mdfind and delete
  • Next by Date: Re: OT: Re: Passing ampersands through a shell script
  • Previous by thread: Re: How do I avoid a Repeat loop to abort upon errors?
  • Next by thread: Re: How do I avoid a Repeat loop to abort upon errors?
  • Index(es):
    • Date
    • Thread