Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@PARADicmSHIFT

This comment has been minimized.

Copy link

PARADicmSHIFT commented Jul 14, 2016

I have taken the main script and put into an Automator workflow. This can then be used as a system service, and assigned a keyboard shortcut with any 3rd party app requirement. With your permission and credit, I'd like to share it.
See here: https://app.box.com/s/36nin8u81h5er4mszzlxni73h7ieh5eq
Many thanks for the code.

@zonetuke

This comment has been minimized.

Copy link

zonetuke commented Aug 8, 2016

I get the following error when running the Automator workflow. Running MacOS 10.11.6.

screen capture 2016-08-07 at 9 50 48 pm

@paulrudy

This comment has been minimized.

Copy link

paulrudy commented Dec 17, 2016

Thanks for this. I made a version that combines the two, testing first if the frontmost window is a message viewer window. Feel free to use.

http://pastebin.com/XjnxZHus

@rafisaar

This comment has been minimized.

Copy link

rafisaar commented Mar 7, 2018

1 - Thanks for this script!
2 - Instead of using Keyboard Maestro, I put the script in an Automator Service which shows up in Mail and I added a keyboard shortcut to it through the System Preferences (like PARADicmSHIFT suggested as well)
3 - I have MailButler installed, which sometimes adds additional buttons after the "Load Remote Content" button.
In the following line from paulrudy's edited script:
set maybeRemoteContentButton to the last button of the maybeRemoteContentGroup
you choose the last button - so in my case this won't work. But the fix is very simple: just change last with first.
The button is actually the 2nd element of the scrollGroup, but it's the 1st button so with my change the code is always correct (in my case).

Thanks!

@LwsBtlr

This comment has been minimized.

Copy link

LwsBtlr commented Apr 16, 2018

This doesn't work when messages are in a thread (well, it only loads content of the first message).

@alecvance

This comment has been minimized.

Copy link

alecvance commented Dec 5, 2019

I combined some of the above ideas (https://gist.github.com/stevenschobert/f559be35190bd432fcce8f4febd713ef#gistcomment-1826177 and https://gist.github.com/stevenschobert/f559be35190bd432fcce8f4febd713ef#gistcomment-1950364) to create this Automator script that will work if the message is seen in a sidepanel or is in a separate window:


on run {input, parameters}
	
	tell application "System Events" to tell process "Mail"
		
		set mainWindow to a reference to the first window
		
		try
			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
			
		on error theError
			# my regularmessage()
			
			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 try
		
		
	end tell
	
	
	return input
end run

@alecvance

This comment has been minimized.

Copy link

alecvance commented Apr 10, 2020

Well for some reason, the script will no longer run successfully in the Services menu. I see the gear icon in the menubar still. It will run successfully from Automator as a workflow, but that's it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.