Repeat loops exiting

Maybe I’m just tired but it seems like I can’t do what I am trying to do. I have a droplet, and then a repeat through all the items you dropped on the droplet. The repeat loop looks to see if it is a valid file before proceeding. If not, I was thinking of using “Return” or “Exit Repeat” to get out of the repeat loop and go on to the next one. Neither does what I want it to. Return jumps it out of the whole “On Open” routine and “Exit Repeat” kills the repeat loop entirely even if there are more items to be processed.

Is there a command I am not thinking of to jump out of the current iteration through the repeat and go on to the next repeat?? If not, I guess I will have to turn the if statement into an if else thing. Just wondering if there is a way to jump out of the repeat.

on open these_items
	repeat with i from 1 to the count of these_items
		set this_item to (item i of these_items)
		tell application "System Events"
			set the item_info to info for this_item
			if not ((kind of item_info starts with "Quark") or (kind of item_info starts with "InDesign")) then
				display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 6
				--exit repeat or return? Here's where I want to go on to the next item in the repeat loop
			end if
		end tell
		--Do a bunch of stuff to the Quark or InDesign file
	end repeat
end open

Model: G5 OSX 10.4.8
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

In other languages, that would be continue, next, etc.; Unfortunately, AppleScript doesn’t have a native command for this. However, you could use a try block to get the same effect. (I’ll have to wait until later to post an example. Edit: I’ve posted one before…)

Matt:
You must be a bit tired since I’ve seen some of your scripting skills in other posts :stuck_out_tongue: Unless I completely misunderstood your question, here ya go:


on open these_items
	repeat with i from 1 to the count of these_items
		set this_item to (item i of these_items)
		tell application "System Events"
			set the item_info to info for this_item
			if not ((kind of item_info starts with "Quark") or (kind of item_info starts with "InDesign")) then
				display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 6
			else
				display dialog "Working on stuff." -- Put your  process here (or in a handler, which is what I usually do.)
				--exit repeat or return? Here's where I want to go on to the next item in the repeat loop
			end if
		end tell
	end repeat
end open

If the file is not valid flag the user else do some other stuff.

Get some sleep,man! :lol:

Jim Neumann
BLUEFROG

P.S. Why the call to System Events? Why not just “Finder”?!? Just curious. - J

OK. Thanks for the quick response. I had a feeling it needed to be an if-else construction. I think I was flashing back to my Commodore 64 BASIC days thinking I could do a NEXT in the middle of the loop.

As far as System Events, that’s how I have always done it. One of those things that once I did it the first time I copied and pasted it into all my later scripts.

Thanks.

No problem. BTW, I don’t have any numbers on this (maybe Adam or Nigel would) but I would reorder your Repeat and Tell block. As it stands you are repeatedly Telling / End Telling System Events to do something. I would put the “tell System Events” outside with the repeat loop inside.

tell Systems Events.
repeat
end repeat
end tell

Once again, no hard facts on it. Just seems cleaner than “I’m talking to you. I’m not talking to you. I’m talking to you. I’m not talking to you. I’m talking to you. I’m not talking to you.”

-Jim

Actually none of them is needed, info for is part of Standard Scripting Addition


on open these_items
	repeat with oneItem in these_items
		set Ki to kind of (info for oneItem)
		if not ((Ki starts with "Quark") or (Ki starts with "InDesign")) then
			display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 6
		else
			display dialog "Working on stuff." -- Put your  process here (or in a handler, which is what I usually do.)
			--exit repeat or return? Here's where I want to go on to the next item in the repeat loop
		end if
	end repeat
end open

http://bbs.applescript.net/viewtopic.php?id=21465

Nitpick: info for has become deprecated in Leopard.

Thanks Bruce, but this is great pity.
in my opinion the advantage of info for is/was just to get the information without involving Finder or System Events

That’s good to know. We will be switching to Leopard at some point so I’ll leave System Events in there.

Here is my final code for what it’s worth. It seemed more logical to put the error part as the “else” so I switched it. I know it doesn’t affect how it runs but it seemed weird to say, if this ISN’T the right file do something, otherwise it’s OK to continue - seems backwards…

	repeat with i from 1 to the count of these_items
		set this_item to (item i of these_items)
		tell application "System Events" to set item_info to info for this_item
		if ((kind of item_info starts with "Quark") or (kind of item_info starts with "InDesign")) then
			if (kind of item_info starts with "InDesign") then
				my process_InDesign_item(this_item)
			else
				my process_Quark_item(this_item)
			end if
		else
			tell application "Finder" to activate
			display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 6
		end if
	end repeat

:lol:

info for .

and

tell application "System Events" to . info for .

is exactly the same. You should tell “System Events” to get the kind of the file directly


repeat with i from 1 to the count of these_items
    set this_item to (item i of these_items)
    tell application "System Events" to set item_kind to kind of this_item
    if item_kind starts with "Quark" then
        process_Quark_item(this_item)
    else if item_kind starts with "InDesign" then
        process_InDesign_item(this_item)
    else
        tell application "Finder" to activate
        display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 6
    end if
end repeat

Cool!

Thanks.