Monday, December 18, 2017

#1 2009-09-12 07:28:12 am

chris2
Member
Registered: 2008-09-10
Posts: 331
Website

Ignore error and continue

Applescript:

set thelist to {}
tell application "System Events"
   set {name:theApp, bundle identifier:theIdentifier} to (get 1st application process whose frontmost is true)
end tell
try
   repeat with i from 2 to 10
       set documentRecords to (do shell script "defaults read " & theIdentifier & " NSRecentDocumentRecords")
       set {TID, text item delimiters} to {text item delimiters, "<"}
       set alis to text item i of documentRecords
       set text item delimiters to ">"
       set alis to text item 1 of alis
       set text item delimiters to space
       set alis to text items of alis
       set text item delimiters to ""
       set alis to (run script "«data alis" & (alis as text) & "»")
       set text item delimiters to TID
       set alis to alis as text
       set end of thelist to alis
   end repeat
   tell me to activate
   set chooseFile to (choose from list thelist with title "Open Recent" with prompt "Choose File(s):" with multiple selections allowed)
   
   set theresult to the result
   if theresult is not false then
       repeat with aitem in theresult
           tell application theApp
               activate
               open aitem
           end tell
       end repeat
   end if
on error e
   tell me to activate
   display dialog e
end try

Frequently, I get errors like "Can't get item 7 of............" because the file may have been moved/deleted by me. I want that in such cases, the remaining items (i.e. items 1 to 6 and 8 to 9/10) should be displayed in the dialog box.
Help please.

Last edited by chris2 (2009-09-12 07:28:35 am)


Tireless endeavour is the effort required to restrict the modifications of the mind
www.thehungersite.com


Filed under: System

Offline

 

#2 2009-09-12 11:23:12 am

Craig Williams
Administrator
From:: Ft. Smith, AR
Registered: 2006-12-07
Posts: 888

Re: Ignore error and continue

You have a try block around the entire workflow. Add another try block around the code in question but leave off the "on error" part.

or

You could check to see if the file exists before trying to use it.

Offline

 

#3 2009-09-12 11:40:48 am

BS0D
Member
Registered: 2008-12-22
Posts: 179

Re: Ignore error and continue

I figured out yesterday that if you leave the on error block "blank" like so :

Applescript:

try
-- your code
on error
-- do nothing to skip the error
end try

... well you get no error at all. At least that worked for me last night smile

The thing is, I think, you have to make sure you identify the part of the code that gives you an error. You need to to try several combinations... and see what works.

Offline

 

#4 2009-09-12 11:47:41 am

Craig Williams
Administrator
From:: Ft. Smith, AR
Registered: 2006-12-07
Posts: 888

Re: Ignore error and continue

BS0D wrote:

I figured out yesterday that if you leave the on error block "blank" like so :

Applescript:

try
-- your code
on error
-- do nothing to skip the error
end try

... well you get no error at all. At least that worked for me last night smile


That is because you did not specify anything to happen when the error occurred. If you are not
going to use the error then it is best to leave it out. This way it is clear to you and anyone else
reading your code that you want to skip any error that may come up.

Applescript:


try
-- your code
end try

Offline

 

#5 2009-09-12 02:08:51 pm

BS0D
Member
Registered: 2008-12-22
Posts: 179

Re: Ignore error and continue

Yeah I hear that, but I jsut didn't know what to do with that error, so I decided to ignore it by using the code I posted.
Let's face it, it's the easy way out but for a newbie like me it works out smile

Offline

 

#6 2009-09-13 12:17:53 am

chris2
Member
Registered: 2008-09-10
Posts: 331
Website

Re: Ignore error and continue

You have a try block around the entire workflow. Add another try block around the code in question but leave off the "on error" part.


I thought about it, I was not sure if a try block within a try block would work. Thanks Craig, I will try it now.

Last edited by chris2 (2009-09-13 12:18:50 am)


Tireless endeavour is the effort required to restrict the modifications of the mind
www.thehungersite.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)