On Sep 20, 2007, at 2:47 PM, Jim DeVona wrote:

Is it possible to use a "whose" clause to get only items of a certain
type from a list of Yojimbo database items?

It sounds like an innocently easy question. But I'm afraid there is no easy, generally applicable answer.

In the case that you want to access an single item class directly, your best bet is to use a whose clause against that item class, such as 'every bookmark item whose <xxx>'.

Here is an example
intended to get any selected bookmark items:

tell application "Yojimbo"
        
        set _items to selected items of browser window 1
        if _items is missing value then return
        
        set _bookmarks to every item of _items whose class is bookmark item
        
end tell

The bookmarks line gives this error: 'Can't get {bookmark item id
"D0303DFD-C8B1-4F17-BD0E-EAD40018D3A1" of application "Yojimbo"} whose
class = bookmark item.' I suspect I am either grossly off track or
nearly there. Any guidance?

The selected items property returns a list of object specifiers. I'm not sure there is a good way to filter that list using a whose clause. (If there is, someone please clue me in.)

If you are iterating the list to do work, you could filter the list as you go and only perform work on the items with the appropriate class. Or you could write a handler to fetch and filter the selected items by class for you. Here's an example:

on GetSelectedItemsOfClass(zItemClass)
        tell application "Yojimbo"
                set zSelectedItems to selected items of browser window 1
                if zItemClass is database item then
                        set zFilteredItems to zSelectedItems
                else
                        set zFilteredItems to {}
                        set zCount to length of zSelectedItems
                        repeat with i from 1 to zCount
                                set zItem to item i of zSelectedItems
                                if class of zItem is zItemClass then
                                        set zFilteredItems to zFilteredItems & 
{zItem}
                                end if
                        end repeat
                end if
                return zFilteredItems
        end tell
end GetSelectedItemsOfClass

tell application "Yojimbo"
        my GetSelectedItemsOfClass(bookmark item)
end tell


- Jim



--
------------------------------------------------------------------
This message is sent to you because you are subscribed to
 the mailing list <[email protected]>.
To unsubscribe, send mail to: <[EMAIL PROTECTED]>
List archives:  <http://www.listsearch.com/yojimbotalk.lasso>
Have a feature request, or not sure if the software's working correctly? Please send mail to: <[EMAIL PROTECTED]>

Reply via email to