def remove(self, to_rm: str) -> None:
        """Removes sidebar list item.

        :param str to_rm: Name of sidebar list item to remove.
        """

        for item in self.snapshot[0]:
            name = LSSharedFileListItemCopyDisplayName(item)
            if to_rm.upper() == name.upper():
                LSSharedFileListItemRemove(self.sflRef, item)
        self.synchronize()
        self.update()
	def remove(self, to_rm):
		"""
		Removes sidebar list item.

		Args:
			to_rm (str): Name of sidebar list item to remove.

		"""
		for item in self.snapshot[0]:
			name = LSSharedFileListItemCopyDisplayName(item)
			if to_rm.upper() == name.upper():
				LSSharedFileListItemRemove(self.sflRef, item)
		self.synchronize()
		self.update()
Beispiel #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
    def move(self, to_mv, after):
        """
        Moves sidebar list item to position immediately other sidebar
        list item.

        Args:
            to_mv (str): Name of sidebar list item to move.
            after (str): Name of sidebar list item to move "to_mv" after.

        """
        if to_mv not in self.favorites.keys() or \
                after not in self.favorites.keys() or to_mv == after:
            return

        for item in self.snapshot[0]:
            name = LSSharedFileListItemCopyDisplayName(item)

            if name == after:
                after = item
            elif name == to_mv:
                to_mv = item

        LSSharedFileListItemMove(self.sflRef, to_mv, after)
        self.synchronize()
        self.update()
Beispiel #5
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 get_name_from_index(self, index: int) -> None:
        """Gets name of sidebar list item identified by index.

        :param int index: Index to identify sidebar list item by.

        :returns: Name of sidebar list item identified by index.
        """

        if index > len(self.snapshot[0]):
            index = -1
        return LSSharedFileListItemCopyDisplayName(self.snapshot[0][index])
    def get_index_from_name(self, name: str) -> int:
        """Gets index of sidebar list item identified by name.

        :param str name: Display name to identify sidebar list item by.

        :returns: Index of sidebar list item identified by name.
        """

        for index, item in enumerate(self.snapshot[0]):
            found_name = LSSharedFileListItemCopyDisplayName(item)
            if name == found_name:
                return index
    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
    def getNameFromIndex(self, index):
        """
		Gets name of sidebar list item identified by index.

		Args:
			index (str): Index to identfy sidebar list item by.

		Returns:
			Name of sidebar list item identified by index.

		"""
        if index > len(self.snapshot[0]):
            index = -1
        return LSSharedFileListItemCopyDisplayName(self.snapshot[0][index])
Beispiel #10
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]
Beispiel #11
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]
    def getIndexFromName(self, name):
        """
		Gets index of sidebar list item identified by name.

		Args:
			name (str): Display name to identfy sidebar list item by.

		Returns:
			Index of sidebar list item identified by name

		"""
        for index, item in enumerate(self.snapshot[0]):
            found_name = LSSharedFileListItemCopyDisplayName(item)
            if name == found_name:
                return index
Beispiel #13
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