robust handling of return values
robust handling of return values
- Subject: robust handling of return values
- From: patrick machielse <email@hidden>
- Date: Fri, 11 Nov 2005 15:21:47 +0100
I've noticed that some AppleScript commands don't return values of 1
predefined type, but can return an 'array' of different things. Most
of the time, there is a choice of:
- 'nothing' returned
- single object returned
- list of objects returned
For example, to add files to an iTunes playlist you use the 'add'
command:
add list of alias : the file(s) to add
[to location reference] : the location of the added file(s)
→ track : reference to added track(s)
Just like the dictionary _doesn't_ say, depending on how many files
were added, the command returns either:
- 'nothing'
- a file track
- a list of file tracks
Now on to my question: how do I robustly check the result value of
the 'add' command?
when I use
set addedTracks to add {list of tracks}
addedTracks is undefined when no tracks were added.
should I use:
set addedTracks to add {list of tracks}
try
get addedTracks
if ( "class of addedTracks is list" )
-- it is a list
else
-- it is a file track
end if
onerror
-- nothing returned
end try
This seems a bit unelegant, using exceptions for flow control. There
must be a better way around this.
A related question: why wouldn't the 'add' command just return an
empty list if no tracks were added? Why make it difficult?
patrick _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden