Re: How do I avoid a Repeat loop to abort upon errors?
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: André Sartori <email@hidden>
- Date: Mon, 26 Oct 2009 08:47:26 +0000
Thank you very much for the replies. That solved my problem!
2009/10/26 Jim Skibbie <email@hidden>:
> 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
--
Andre F Sartori
Department of Earth Sciences
University of Cambridge
Downing Street
Cambridge
CB2 3EQ
_______________________________________________
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