Bulk hook email messages


I’m using Apple mail and wondering if there is a way to select multiple messages and hook them all at once with the other document.

I think when I try to do that right now it just hook only one message.

Is there any workaround, option or script I can use?
This is also useful for older set of email I want to use hook with.

Sorry for now it is not possible from Hookmark window.

Here is a workaround. You can use AppleScript to get all selected messages markdown links and use Hook to copied link to link them to the other document.

The following script will copy the selected messages markdown links to the clipboard. After you run the script, invoke Hookmark on the other document, do command+v or click the menu item “Hook to copied link”.

-- set longFormName to false to exclude source, destination and date from the names of links to email
global longFormName
global placeMetaDataBeforeSubject
set longFormName to true
set placeMetaDataBeforeSubject to false

-- you may replace these labels if you like, such as "de" and "à" respectively in French
global sourceLabel
global destinationLabel
set sourceLabel to "From"
set destinationLabel to "to"

tell application "Mail"
	set frontWinIsMessageViewer to false
	set fid to id of front window
	repeat with v in message viewers
		set wid to id of window of v
		if fid = wid then
			set frontWinIsMessageViewer to true
		end if
	end repeat
	if frontWinIsMessageViewer then
			set theSelection to selection
			set selectedMarkdownLinks to ""
			repeat with theMessage in theSelection
				set mid to message id of theMessage
				set mid to my encodeText(mid, true, false)
				set sub to subject of theMessage
				set mTitle to my getMessageTitle(sub, theMessage)
				set selectedMarkdownLinks to selectedMarkdownLinks & "[" & mTitle & "](" & "email://" & mid & ")
			end repeat
			set the clipboard to selectedMarkdownLinks
		on error eStr number enum
			display dialog eStr & "step 1"
		end try
	end if
end tell

on encodeText(theText, encodeCommonSpecialCharacters, encodeExtendedSpecialCharacters)
	set theStandardCharacters to "abcdefghijklmnopqrstuvwxyz0123456789"
	set theCommonSpecialCharacterList to "$+!'/?;&@=#%><{}\"~`^\\|*"
	set theExtendedSpecialCharacterList to ".-_:"
	set theAcceptableCharacters to theStandardCharacters
	if encodeCommonSpecialCharacters is false then set theAcceptableCharacters to theAcceptableCharacters & theCommonSpecialCharacterList
	if encodeExtendedSpecialCharacters is false then set theAcceptableCharacters to theAcceptableCharacters & theExtendedSpecialCharacterList
	set theEncodedText to ""
	repeat with theCurrentCharacter in theText
		if theCurrentCharacter is in theAcceptableCharacters then
			set theEncodedText to (theEncodedText & theCurrentCharacter)
			set theEncodedText to (theEncodedText & encodeCharacter(theCurrentCharacter)) as string
		end if
	end repeat
	return theEncodedText
end encodeText

on encodeCharacter(theCharacter)
	set theASCIINumber to (the ASCII number theCharacter)
	set theHexList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
	set theFirstItem to item ((theASCIINumber div 16) + 1) of theHexList
	set theSecondItem to item ((theASCIINumber mod 16) + 1) of theHexList
	return ("%" & theFirstItem & theSecondItem) as string
end encodeCharacter

on getMessageTitle(subj, theMessage)
	tell application "Mail"
		set subj to subject of theMessage
		if longFormName is false then
			return subj
		end if
			set c to count of to recipients of theMessage
			if c > 0 then
				set toMail to address of item 1 of to recipients of theMessage
				set toMail to ""
			end if
			set fromMail to extract address from sender of theMessage
			set d to date received of theMessage
			set mon to month of d as number
			if mon < 10 then
				set mon to "0" & mon
			end if
			set yy to year of d as string
			set dd to day of d as string
			set d to (yy & "-" & mon & "-" & dd)
			if placeMetaDataBeforeSubject then
				set subj to d & " " & sourceLabel & " " & fromMail & " " & destinationLabel & " " & toMail & " " & subj
				set subj to subj & " [[" & d & "]] " & sourceLabel & " " & fromMail & " " & destinationLabel & " " & toMail
			end if
		end try
		return subj
	end tell
end getMessageTitle

Should it be ER or new feature request?

New feature request, I think. I will submit an issue for this feature request.

Thank you

Awesome script. Thanks a lot.