- 
      
- 
        Save stevenschobert/f559be35190bd432fcce8f4febd713ef to your computer and use it in GitHub Desktop. 
| 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 | 
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
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.
The script doesn't work anymore on MacOS 10.14.6. Script Editor says:
error "System Events got an error: Can’t get window 1 of process "Mail". Invalid index." number -1719 from window 1 of process "Mail"
Does anyone know how to update it?
Thank you for this script! It was driving me crazy that there is no menu item for this action.
This doesn't work when messages are in a thread (well, it only loads content of the first message).