Last active
March 26, 2025 06:24
-
-
Save April-June-August/018aae91fd0271772e7add415ba63c5c to your computer and use it in GitHub Desktop.
Create an Hide My Email email address in System Settings. Search for an Hide My Email email address in System Settings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/osascript -l JavaScript | |
// Tested March 15, 2025 | |
// macOS Sequoia 15.3.2 (24D81) | |
// Link: https://gist.github.com/April-June-August/018aae91fd0271772e7add415ba63c5c/ | |
// Author: May-June-July | |
ObjC.import("AppKit") | |
function launchSettingsPane(pane) { | |
const url = $.NSURL.URLWithString("x-apple.systempreferences:" + pane) | |
$.NSWorkspace.sharedWorkspace.openURL(url) | |
} | |
// Click button | |
function clickButton(button, retries = 150) { | |
for (let i = 0; i < retries; i++) { | |
delay(0.1) | |
try { | |
if (!button.enabled()) { continue; } else { delay(0.3) } | |
button.click() | |
return true | |
} catch {} | |
} | |
return false | |
} | |
// Populate text field | |
function fillTextField(textField, value, retries = 150) { | |
for (let i = 0; i < retries; i++) { | |
delay(0.1) | |
try { | |
textField.click() | |
textField.value = value | |
return true | |
} catch {} | |
} | |
return false | |
} | |
// Wait for button to disappear | |
function waitForButtonToDisappear(button, maxRetries = 100) { | |
for (let i = 0; i < maxRetries; i++) { | |
delay(0.1); | |
try { | |
// Attempt to access any button property | |
button.name(); // This will throw if element is gone | |
} catch (e) { | |
// Button is no longer present in UI hierarchy | |
return true; | |
} | |
} | |
// Button still exists after maximum retries | |
return false; | |
} | |
function run(args) { | |
const label = args[0]; | |
// --------------------------------------- | |
// iCloud -> Hide My Email | |
launchSettingsPane("com.apple.systempreferences.AppleIDSettings: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(3) | |
var hideMyEmailButtonClickResult = clickButton(hideMyEmailButton) | |
if ( hideMyEmailButtonClickResult ) { console.log("“Hide My Email” button clicked") } | |
else { console.log("⚠️ Failed: “Hide My Email” button not clicked"); return false } | |
// --------------------------------------- | |
// iCloud -> Hide My Email -> Create New Address | |
const createNewAddressButton = Application("System Events") | |
.applicationProcesses.byName("System Settings") | |
.windows.byName("iCloud") | |
.sheets.at(0) | |
.scrollAreas.at(0) | |
.uiElements.at(0) | |
.groups.at(0) | |
.groups.at(0) | |
.groups.at(0) | |
.buttons.byName("Create New Address") | |
var createNewAddressButtonClickResult = clickButton(createNewAddressButton) | |
if ( createNewAddressButtonClickResult ) { console.log("“Create New Address” button clicked") } | |
else { console.log("⚠️ Failed: “Create New Address” button not clicked"); return false } | |
// --------------------------------------- | |
// iCloud -> Hide My Email -> Create New Address -> Label | |
const labelTextField = Application("System Events") | |
.applicationProcesses.byName("System Settings") | |
.windows.byName("iCloud") | |
.sheets.at(0) | |
.scrollAreas.at(0) | |
.uiElements.at(0) | |
.groups.at(0) | |
.groups.at(0) | |
.groups.at(3) | |
.textFields.at(0) | |
var textFieldFillResult = fillTextField(labelTextField, label) | |
if ( textFieldFillResult ) { console.log("“Label” text field filled") } | |
else { console.log("⚠️ Failed: “Label” text field not filled"); return false } | |
// --------------------------------------- | |
// iCloud -> Hide My Email -> Create New Address -> Label -> Continue | |
const continueButton = Application("System Events") | |
.applicationProcesses.byName("System Settings") | |
.windows.byName("iCloud") | |
.sheets.at(0) | |
.scrollAreas.at(0) | |
.uiElements.at(0) | |
.groups.at(0) | |
.groups.at(1) | |
.groups.at(0) | |
.groups.at(1) | |
.buttons.byName("Continue") | |
var continueClickResult = clickButton(continueButton) | |
if ( continueClickResult ) { console.log("“Continue” button clicked") } | |
else { console.log("⚠️ Failed: “Continue” button not clicked"); return false} | |
// Wait for “Continue” button to disappear | |
var continueDisappearResult = waitForButtonToDisappear(continueButton) | |
if ( continueDisappearResult ) { console.log("“Continue” button disappeared") } | |
else { console.log("⚠️ Failed: “Continue” button not disappeared"); return false} | |
// --------------------------------------- | |
// iCloud -> Hide My Email -> Create New Address -> Label -> Continue -> Copy Address | |
const copyAddressButton = Application("System Events") | |
.applicationProcesses.byName("System Settings") | |
.windows.byName("iCloud") | |
.sheets.at(0) | |
.scrollAreas.at(0) | |
.uiElements.at(0) | |
.groups.at(0) | |
.groups.at(1) | |
.groups.at(0) | |
.groups.at(0) | |
.buttons.byName("Copy Address") | |
var copyAddressClickResult = clickButton(copyAddressButton) | |
if ( copyAddressClickResult ) { console.log("“Copy Address” button clicked") } | |
else { console.log("⚠️ Failed: “Copy Address” button not clicked"); return false } | |
// --------------------------------------- | |
// iCloud -> Hide My Email -> Create New Address -> Label -> Continue -> Copy Address -> Done | |
const doneButton = Application("System Events") | |
.applicationProcesses.byName("System Settings") | |
.windows.byName("iCloud") | |
.sheets.at(0) | |
.scrollAreas.at(0) | |
.uiElements.at(0) | |
.groups.at(0) | |
.groups.at(1) | |
.groups.at(0) | |
.groups.at(1) | |
.buttons.byName("Done") | |
var doneClickResult = clickButton(doneButton) | |
if ( doneClickResult ) { console.log("First “Done” button clicked") } | |
else { console.log("⚠️ Failed: First “Done” button not clicked"); return false } | |
// Wait for first “Done” button to disappear | |
var doneDisappearResult = waitForButtonToDisappear(doneButton) | |
if ( doneDisappearResult ) { console.log("First “Done” button disappeared") } | |
else { console.log("⚠️ Failed: First “Done” button not disappeared"); return false} | |
// --------------------------------------- | |
// iCloud -> Hide My Email -> Create New Address -> Label -> Continue -> Copy Address -> Done -> Done | |
const doneButton2 = Application("System Events") | |
.applicationProcesses.byName("System Settings") | |
.windows.byName("iCloud") | |
.sheets.at(0) | |
.scrollAreas.at(0) | |
.uiElements.at(0) | |
.groups.at(0) | |
.groups.at(1) | |
.groups.at(0) | |
.groups.at(0) | |
.buttons.byName("Done") | |
var done2ClickResult = clickButton(doneButton2) | |
if ( done2ClickResult ) { console.log("Second “Done” button clicked") } | |
else { console.log("⚠️ Failed: Second “Done” button not clicked"); return false} | |
// Wait for second “Done” button to disappear | |
var done2disappearResult = waitForButtonToDisappear(doneButton2) | |
if ( done2disappearResult ) { console.log("Second “Done” button disappeared") } | |
else { console.log("⚠️ Failed: Second “Done” button not disappeared"); return false } | |
// --------------------------------------- | |
// Quit System Settings | |
delay(0.5); | |
const systemSettings = Application("System Settings"); | |
systemSettings.quit(); | |
// Verify quit succeeded | |
let isQuit = false; | |
for (let i = 0; i < 10; i++) { // Check up to 5 seconds | |
delay(0.5); | |
if (!systemSettings.running()) { | |
isQuit = true; | |
break; | |
} | |
} | |
if (isQuit) { | |
console.log("✅️ System Settings quit successfully"); | |
return true; | |
} else { | |
console.log("⚠️ Failed to quit System Settings"); | |
return false; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/osascript -l JavaScript | |
// Tested March 15, 2025 | |
// macOS Sequoia 15.3.2 (24D81) | |
// Link: https://gist.github.com/April-June-August/018aae91fd0271772e7add415ba63c5c/ | |
// Author: May-June-July | |
ObjC.import("AppKit") | |
function launchSettingsPane(pane) { | |
const url = $.NSURL.URLWithString("x-apple.systempreferences:" + pane) | |
$.NSWorkspace.sharedWorkspace.openURL(url) | |
} | |
// Click button | |
function clickButton(button, retries = 150) { | |
for (let i = 0; i < retries; i++) { | |
delay(0.1) | |
try { | |
if (!button.enabled()) { continue; } else { delay(0.3) } | |
button.click() | |
return true | |
} catch {} | |
} | |
return false | |
} | |
// Populate text field | |
function fillTextField(textField, value, retries = 150) { | |
for (let i = 0; i < retries; i++) { | |
delay(0.1) | |
try { | |
textField.click() | |
textField.value = value | |
return true | |
} catch {} | |
} | |
return false | |
} | |
// Wait for button to disappear | |
function waitForButtonToDisappear(button, maxRetries = 100) { | |
for (let i = 0; i < maxRetries; i++) { | |
delay(0.1); | |
try { | |
// Attempt to access any button property | |
button.name(); // This will throw if element is gone | |
} catch (e) { | |
// Button is no longer present in UI hierarchy | |
return true; | |
} | |
} | |
// Button still exists after maximum retries | |
return false; | |
} | |
function run(args) { | |
const label = args[0]; | |
// --------------------------------------- | |
// iCloud -> Hide My Email | |
launchSettingsPane("com.apple.systempreferences.AppleIDSettings: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(3) | |
var hideMyEmailButtonClickResult = clickButton(hideMyEmailButton) | |
if ( hideMyEmailButtonClickResult ) { console.log("“Hide My Email” button clicked") } | |
else { console.log("⚠️ Failed: “Hide My Email” button not clicked"); return false } | |
// --------------------------------------- | |
// iCloud -> Hide My Email -> Search | |
const searchTextField = Application("System Events") | |
.applicationProcesses.byName("System Settings") | |
.windows.byName("iCloud") | |
.sheets.at(0) | |
.scrollAreas.at(0) | |
.uiElements.at(0) | |
.groups.at(0) | |
.groups.at(0) | |
.groups.at(0) | |
.groups.at(1) | |
.textFields.at(0) | |
var textFieldFillResult = fillTextField(searchTextField, label) | |
if ( textFieldFillResult ) { console.log("“Label” text field filled") } | |
else { console.log("⚠️ Failed: “Label” text field not filled"); return false } | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment