def __init__(self):
     self.sflRef = LSSharedFileListCreate(kCFAllocatorDefault,
                                          kLSSharedFileListFavoriteItems,
                                          None)
     self.snapshot = LSSharedFileListCopySnapshot(self.sflRef, None)
     self.favorites = dict()
     self.update()
Exemple #2
0
def _get_login_items():
    # Setup the type of shared list reference we want
    list_ref = LSSharedFileListCreate(None, kLSSharedFileListSessionLoginItems, None)
    # Get the user's login items - actually returns two values, with the second being a seed value
    # indicating when the snapshot was taken (which is safe to ignore here)
    login_items,_ = LSSharedFileListCopySnapshot(list_ref, None)
    return [list_ref, login_items]
Exemple #3
0
def items(context):
    '''
    Get a list of 'Login Items'

    context
        The shared file list context: 'user' (meaning the current session) or 'system'.
        The default login item list will be the 'system' list.

    CLI Example:

    .. code-block:: bash

        salt '*' login.items [context]
    '''
    if context == 'user':
        defined_context = kLSSharedFileListSessionLoginItems
    else:
        defined_context = kLSSharedFileListGlobalLoginItems

    log.info('Getting login items for the %s context', 'user' if context == 'user' else 'system')
    lst = LSSharedFileListCreate(None, defined_context, None)
    snapshot, seed = LSSharedFileListCopySnapshot(lst, None)  # snapshot is CFArray

    log.info('Login item display names:')
    login_items = [LSSharedFileListItemCopyDisplayName(item) for item in snapshot]
    log.info(login_items)

    return login_items
Exemple #4
0
    def _find_item_in_list(self, lst, name):
        from LaunchServices import LSSharedFileListCopySnapshot
        from LaunchServices import LSSharedFileListItemCopyDisplayName

        for item in LSSharedFileListCopySnapshot(lst, None)[0]:
            if name == LSSharedFileListItemCopyDisplayName(item):
                return item

        return None
    def update(self) -> None:
        """Updates snapshot and favorites attributes.
        """

        self.favorites = dict()
        self.snapshot = LSSharedFileListCopySnapshot(self.sflRef, None)
        for item in self.snapshot[0]:
            name = LSSharedFileListItemCopyDisplayName(item)
            path = ""
            if name not in ["AirDrop", "All My Files", "iCloud"]:
                path = LSSharedFileListItemResolve(item, 0, None, None)[1]
            self.favorites[name] = path
Exemple #6
0
def devices():
    '''
    Get items listed as Finder devices, this normally appears on the sidebar.
    This would normally return mounted devices for root, but since mounts are usually system wide, this will be ok.

    CLI Example::

        salt '*' finder.devices
    '''
    lst = LSSharedFileListCreate(None, kLSSharedFileListFavoriteVolumes, None)
    snapshot, seed = LSSharedFileListCopySnapshot(lst,
                                                  None)  # snapshot is CFArray

    return [LSSharedFileListItemCopyDisplayName(item) for item in snapshot]
Exemple #7
0
def favorites():
    '''
    Get items listed as Finder favorites, this normally appears on the sidebar.
    Because the minion runs as root, this function returns sidebar items for root which is not terribly useful.

    CLI Example::

        salt '*' finder.favorites
    '''
    lst = LSSharedFileListCreate(None, kLSSharedFileListFavoriteItems, None)
    snapshot, seed = LSSharedFileListCopySnapshot(lst,
                                                  None)  # snapshot is CFArray

    return [LSSharedFileListItemCopyDisplayName(item) for item in snapshot]
Exemple #8
0
 def _find_item_in_list(lst: List[str], name: str) -> Optional[str]:
     for item in LSSharedFileListCopySnapshot(lst, None)[0]:
         item_name = LSSharedFileListItemCopyDisplayName(item)
         if name == item_name:
             return item
     return None