Skip to content

Instantly share code, notes, and snippets.

@stevenschobert
Last active January 12, 2022 11:19
Show Gist options
  • Save stevenschobert/f559be35190bd432fcce8f4febd713ef to your computer and use it in GitHub Desktop.
Save stevenschobert/f559be35190bd432fcce8f4febd713ef to your computer and use it in GitHub Desktop.
Apple Script to click the "Load Remote Content" button. I like to disable all remote content in Mail.app, and then bind this script to a keyboard shortcut using Keyboard Maestro. https://www.keyboardmaestro.com
tell application "System Events" to tell process "Mail"
set mainWindow to a reference to the first window
set rootSplitter to a reference to the first splitter group of the mainWindow
set firstSplitter to a reference to the last splitter group of the rootSplitter
set scrollArea to a reference to the last scroll area of the firstSplitter
set scrollGroup to a reference to the first group of the scrollArea
if number of groups of the scrollGroup is greater than 1 then
set maybeRemoteContentGroup to a reference to the first group of the scrollGroup
if number of buttons of the maybeRemoteContentGroup is greater than or equal to 1 then
set maybeRemoteContentButton to a reference to the last button of the maybeRemoteContentGroup
if name of the maybeRemoteContentButton contains "load remote content" then
click the maybeRemoteContentButton
else
name of the maybeRemoteContentButton
end if
else
UI elements of maybeRemoteContentGroup
end if
else
UI elements of the scrollGroup
end if
end tell
tell application "System Events" to tell process "Mail"
set mainWindow to the first window
set mainScrollGroup to the first scroll area of the mainWindow
set everyMessage to every group of the mainScrollGroup
log (number of everyMessage)
repeat with currentMessage in everyMessage
set loadRemoteContentButton to the first button of the first group in the currentMessage
click the loadRemoteContentButton
end repeat
end tell
@nicolaibach
Copy link

Thank you for this script! It was driving me crazy that there is no menu item for this action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment