Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Adding existing items to to-many relationship
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding existing items to to-many relationship




On 7 Feb 2008, at 10:54 PM, Jim Correia wrote:

On Feb 6, 2008, at 6:51 AM, Christiaan Hofman wrote:

So is this the proper way to implement what I want? If not what can I do otherwise? I cannot think of any other way to do it. And writing a custom 'add' command is quite a bit of work and seems like duplication to me.

If your object model is not a strict hierarchy, but instead has items which can either be freestanding or associated with multiple containers (like playlists in iTunes, albums in iPhoto, etc.), then add/remove is the correct way to solve this problem.


This is covered in the Scripting Interface Guidelines:

	<http://developer.apple.com/technotes/tn2002/tn2106.html>

Jim

Thanks, I forgot about that. Too long ago I've looked at that.

If I would create my own add command, I have a few additional; questions (after trying to implement it).

1. The TN says that if the "to" parameter is missing, it makes sense to infer it from the target. That's actually a behavior that makes sense for my app, so I can say

tell group 1
	add foo 1
end tell

But I have no idea how to get the target out of the NSScriptCommand. None of the accesors give it, and I also cannot see it in the - appleEvent description. Even using private methods to interpret the 'subj' gives nothing.

2. If a script would try to add an item from another document to a group from a document, there is a problem, because an item can be contained in only a single document (the document is the default container of an item). So like:

set aFoo to foo 1 of document 2
add aFoo to group 2

So just adding would lead to inconsistencies in my model. I could find 2 ways to solve this: Refuse to do this, either by doing nothing, or by raising an error. Or I could actually add a copy and make sure the copy is added to the document (in this case to document 1). The first case makes sense because the user would also have the 'duplicate' command, which would be more appropriate. What would be the proper way to handle this?

3. I'd like to have both the direct parameter and the "to" parameter to have varying content. It makes sense for the "to" parameter to be either a location specifier (NSPositionSpecifier) or a container (like 'group 1'). So what should the type of it be? It seems to me that making it a multiple type (like 'location specifier' or 'specifier') would lead AppleScript to confusions, as 'group 1' can be interpreted both as a location specifier and as a container (I want it to be a comtainer of course, but AppleScript cannot know this). However if I type it as 'any' I have the problem that AppleScript always gives a AppleEventDescriptor, and Apple has not made their AppleEventDescriptor translation mechanism public (I really hate that). So how should I type it to support both? There is a similar problem for the direct parameter, as I also want to allow some build-in types like files.

Thanks,

Christiaan

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Adding existing items to to-many relationship (From: Christiaan Hofman <email@hidden>)
 >Re: Adding existing items to to-many relationship (From: Jim Correia <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.