Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 9, 2012, 06:30 PM   #1
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Repeat loop weirdness

I noticed some odd behaviour when copying some code from ScriptEditor to a Run Applescript action in Automator.

This example code runs fine in Scripteditor :

Code:
set numberList to {"1", "2", "3"}
repeat with i from 1 to number of items in numberList
	set this_item to item i of numberList
	display dialog this_item giving up after 3
end repeat
When copied to the Run Applescript action in Automator it changes into this when compiled :

Code:
set numberList to {"1", "2", "3"}
repeat with i from 1 to number of items of numberList
	set this_item to item i of numberList
	display dialog this_item giving up after 3
end repeat
The "of" between number and items is no longer bold and the "in" changed to of. When run it errors with the following message :

Syntax Error

No result was returned from some part of this expression.

The solution is to change the code to this :

Code:
set numberList to {"1", "2", "3"}
repeat with i from 1 to count of items of numberList
	set this_item to item i of numberList
	display dialog this_item giving up after 3
end repeat
Why does this happen? Can someone shed some light on this? Thanks.
Attached Thumbnails
Click image for larger version

Name:	Picture 4.png
Views:	36
Size:	64.8 KB
ID:	352284   Click image for larger version

Name:	Picture 5.png
Views:	30
Size:	20.2 KB
ID:	352285  
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Aug 9, 2012, 06:40 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Why not just switch to the more concise:
Code:
repeat with each_item in numberList
	display dialog each_item giving up after 3
end repeat
The form is:
Code:
repeat with listVar in someList
Search for Repeat with listVar in this doc:
http://oreilly.com/catalog/aplscptian/chapter/ch07.html


EDIT
If you insist on using counted loops, consider using the shorter:
Code:
count of listName
Reference doc:
https://developer.apple.com/library/...aslr_cmds.html

It's superfluously prolix to write:
Code:
count of items of listName

Last edited by chown33; Aug 9, 2012 at 07:15 PM.
chown33 is offline   0 Reply With Quote
Old Aug 9, 2012, 08:12 PM   #3
kryten2
Thread Starter
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Thanks for the reply chown33. Clear as ever. Had to lookup the meaning of superfluously prolix. Got it now.
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Songs Repeat Even Though Repeat is Off melissapete24 iOS 7 14 Jul 10, 2014 05:12 PM
iPhone: Repeat Notification The Tos Jailbreaks and iOS Hacks 0 Jan 28, 2014 07:44 AM
Recovery Loop | Cant get iPhone 5 6.1.3 out of loop Fatush iPhone Tips, Help and Troubleshooting 1 Sep 19, 2013 09:14 PM
iPhone: iPHone 4 stuck in DFU loop then boot loop then DFU loop! urbanmacUser Jailbreaks and iOS Hacks 1 Jun 7, 2013 04:30 PM
iPhone 4 Stuck on restore loop, Help! I'm stuck on anger and frustration loop! vegas60 iPhone Tips, Help and Troubleshooting 3 Nov 8, 2012 08:49 AM

Forum Jump

All times are GMT -5. The time now is 01:51 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC