You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using docklib to configure the dock upon login after end users walk through the macOS Setup Assistant. In order to make my script idempotent, I'm searching for existing dock items in order to dynamically determine whether the dock requires customization. Some of the items I'm searching for are Apple default apps: Notes, Messages, Music, Reminders, etc.
This works fine as long as the user has selected English as their preferred language. However, when another language is selected, the Dock item labels are localized in that language — e.g. Notas, Mensajes, Música, Recordatorios — and my script fails.
My workaround has been to use the _CFURLString of the dock items for the basis of comparison, since the apps' path on disk is not affected by localization. However, docklib doesn't make this easy for me, since its current functions are focused on finding, removing, and replacing items based on file-label.
Proposed Solution
I would propose making a new findExistingEntry function that allows finding items by either label (default), path, or basename:
deffindExistingEntry(self, search_str, by="label", section="persistent-apps"):
section_items=self.items[section]
ifsection_items:
forindex, iteminenumerate(section_items):
urlstring=unquote(
item["tile-data"].get("file-data", {}).get("_CFURLString", "")
)
ifby=="label":
# Most dock items use "file-label", but URLs use "label"forlabel_keyin ("file-label", "label"):
ifitem["tile-data"].get(label_key) ==search_str:
returnindexelifby=="path"andurlstring:
ifurlparse(urlstring.rstrip("/")).path==search_str:
returnindexelifby=="basename"andurlstring:
if (
os.path.basename(urlparse(urlstring.rstrip("/")).path)
==search_str
):
returnindexreturn-1
And modifying the findExistingLabel function to serve as a pointer to the new function:
I’m still thinking about how removeDockEntry, replaceDockEntry, and other label-centric functions should be adapted. Open to feedback if anybody has strong opinions.
The text was updated successfully, but these errors were encountered:
Problem
I'm using docklib to configure the dock upon login after end users walk through the macOS Setup Assistant. In order to make my script idempotent, I'm searching for existing dock items in order to dynamically determine whether the dock requires customization. Some of the items I'm searching for are Apple default apps: Notes, Messages, Music, Reminders, etc.
This works fine as long as the user has selected English as their preferred language. However, when another language is selected, the Dock item labels are localized in that language — e.g. Notas, Mensajes, Música, Recordatorios — and my script fails.
My workaround has been to use the
_CFURLString
of the dock items for the basis of comparison, since the apps' path on disk is not affected by localization. However, docklib doesn't make this easy for me, since its current functions are focused on finding, removing, and replacing items based onfile-label
.Proposed Solution
I would propose making a new
findExistingEntry
function that allows finding items by either label (default), path, or basename:And modifying the
findExistingLabel
function to serve as a pointer to the new function:I’m still thinking about how
removeDockEntry
,replaceDockEntry
, and other label-centric functions should be adapted. Open to feedback if anybody has strong opinions.The text was updated successfully, but these errors were encountered: