Klizzy Posted June 7 Posted June 7 Hello Alfred community, i created a new workflow, so its easier to generate new iCloud hide my mail addresses directly trough Alfred. Most of the time you get the native prompt from MacOS if you set your cursor into an input type field "mail" if its marked correctly, but it happens pretty often that the native prompt does not pop up. If you still want to use an iCloud+ hide my mail address, you have to click up to 8-10 times trough the settings to generate and copy a new one, so i automated it with an applescript file & Alfred. The source, more detailed information and an showcase how it looks like, can be found in the GitHub repository: https://github.com/Klizzy/alfred-hide-my-mail Im happy to get some feedback, because that's my first workflow, which i released to the public and it would be great to be also included in the Alfred Gallery. All my previous workflows were only for niche and for private use. Key information extracted from the readme Usage 1. Open Alfred (default shortcut: `Option + Space`). 2. Type `hide` followed by the label you want to assign to the new iCloud Hide My Mail address. 3. Press `Enter`. 4. Press `CMD + V` to paste the generated iCloud Hide My Mail address. Alfred config Workflow screenshot Thanks a lot!
vitor Posted June 7 Posted June 7 Welcome @Klizzy, Nice first submission! My first suggestion would be to replace the config. It’s currently a Text Field but it should be a Popup Selection because you only want users to select from a few pre-defined sources. Also, adding a user-configurable keyword. The second suggestion, and this one is trickier, is handling latency. I also have something like this locally (though I only need the panel, not the auto-creation) but the way I do it is language-agnostic because I’m clicking on elements by index instead of by name. The tradeoff is that if Apple changes the position of anything in a later macOS version, it will need a fix. Neither solution is better, just a choice. But I digress, the point is that all those GUI interactions take a while to execute. And Hide My Mail is slow. I tried your workflow a couple of times and it didn’t quite reach the end as the delays weren’t enough. In general, relying on fixed wait times for some GUI thing to finish is error-prone. My suggestion is to identify the click target, loop a short delay until it is available, and only then try to click it. Klizzy 1
Klizzy Posted June 8 Author Posted June 8 Hello @vitor, thanks for the fast and valuable feedback! The suggested Alfred settings will definitely increase the user experience and reduce the options for not supported settings. The development of the Applescript was definitely the hardest part for me, because the official documentation and many example resources are pretty outdated. For debugging and development purposes i tried UI Browser, Keyboard Maestro, Accessibility selector and some UI debugging applescripts which i found online. UI Browser was pretty useful for debugging the general MacOS UI, but it seems that the iCloud+ Hide My Mail window differs in terms of structure, because UI Browser did not supported it. In my initial approach i tried to identify the UI elements by their IDs, so no language configuration has to be set anymore, but i could simply not locate them with the tools which i found online. Do you have any recommendations for debugging or developing with applescript? My use case is pretty simple, because it only clicks on a couple buttons, but without a proper IDE or debugger it feels pretty clunky. Im a software engineer myself, but its the first time i have dipped my toes into applescript, so any tips a better developer experience are appreciated. It would be great if you could provide additional information regarding the failed workflow in your tests: Did the workflow successfully generated a new mail, or did it failed already beforehand? What MacOS version and device / chip did you use? e.g Macbook Pro 2023, M2 Max
vitor Posted June 12 Posted June 12 On 6/8/2024 at 2:46 AM, Klizzy said: because the official documentation and many example resources are pretty outdated. Tell me about it! On 6/8/2024 at 2:46 AM, Klizzy said: Do you have any recommendations for debugging or developing with applescript? Not exactly. I just painstakingly learned about it over years and developed a style focused on consistency and correctness (as much as that can be achieved) and leveraging the Objective-C bridge a lot to avoid quirks of the language and enhance what it can do. That involves another rabbit hole on its own, learning to properly read Apple’s API docs and understanding the logic of the conversion to JXA. But I can show you what I use and answer specific questions. It’s JXA (JavaScript for Automation, part of the AppleScript family). ObjC.import("AppKit") function launchSettingsPane(pane) { const url = $.NSURL.URLWithString("x-apple.systempreferences:" + pane) $.NSWorkspace.sharedWorkspace.openURL(url) } launchSettingsPane("com.apple.preferences.AppleIDPrefPane?iCloud") const hideMyEmailButton = Application("System Events") .applicationProcesses .byName("System Settings") .windows.byName("iCloud") .groups.at(0) .splitterGroups.at(0) .groups.at(1) .groups.at(0) .scrollAreas.at(0) .groups.at(2) .buttons.at(1) for (let retries = 0; retries < 50; retries++) { delay(0.1) try { hideMyEmailButton.click() break } catch {} } The loop is a workaround to try to press the button only after it’s available, as soon as possible, while still aborting if it takes too long. To get the exact button, I got to the exact pane and did (note the last method: entireContents()): Application("System Events") .applicationProcesses.byName("System Settings") .windows.byName("iCloud") .entireContents() Then waded through that with some deduction and trial and error. Try searching for button and add click() to one of them once in a while to find your “position” in the array of options. Klizzy 1
Klizzy Posted June 16 Author Posted June 16 Thanks again for the awesome support and feedback! Im really impressed to see how supportive and helpful this forum is. Quote Tell me about it! I was taking about the official documentation from apple for applescript, because it has been archived, like seen here: https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html But thanks to sites like macscripter.net, apple.stackexchange.com and the application UI Browser i was able to better debug & develop the script. Im glad to hear that JXA is your preferred choice in that case, because i stumbled around many threads that mentioned that JXA is limited in terms of functionality in comparison to Applescript. Probably also outdated information, which i have found. In the meantime i updated the applescript within the workflow, following your previous recommendations. Its no longer depended on the OS language, has a workflow configuration option to set a custom trigger keyword and the buttons are now identified by their IDs. I found the IDs thanks to the UI Browser application, so i had not to rewrite the whole script. I know that the short static delay times to wait for the System Settings application to appear is not the best possible solution, but it should now get the job done. I would be happy to hear if the new release is now also working on your system. The updated applescript and the new Alfred workflow release had been added to the repository: https://github.com/Klizzy/alfred-hide-my-mail
vitor Posted September 17 Posted September 17 @Klizzy Sequoia changed the pane location, as well as the button. To save you some trouble, the new pane is com.apple.systempreferences.AppleIDSettings:icloud and the first button to click is at Application("System Events").applicationProcesses.byName("System Settings").windows.byName("iCloud").groups.at(0).splitterGroups.at(0).groups.at(1).groups.at(0).scrollAreas.at(0).groups.at(2).buttons.at(3).
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now