Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'use file:// and AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
use file:// and AppleScript
Authored by: tbdavis on Apr 12, '07 11:49:11PM

This is a longer script, but it's pretty fast, and the URL opens very quickly in Mail.app and without the need for any third party software, which is not to say it's better, just different.

Save this file to ~/Library/Scripts/Applications/Mail/Get_Message_URL.scpt to have the AppleScript menu item appear only when Mail is the current application.


-- gets file: URLs for selected messages
using terms from application "Mail"
	
	-- If run from the Scripts menu
	on perform mail action with messages selectedMsgs
		set msgURLs to ""
		set doClipBoard to "Copy to clipboard"
		tell application "Mail"
			if (count of selectedMsgs) is equal to 0 then
				set msgURLs to "There are no selected messages."
				display dialog msgURLs with title "Message URLs" buttons {"Ok"} default button 1 with icon note giving up after 360
				return
			end if
			repeat with msg in selectedMsgs
				set mb to mailbox of msg
				set acctType to account type of account of mb
				set acctSuffix to ""
				if acctType is equal to imap then
					set acctSuffix to ".imapmbox"
				else if acctType is equal to Mac then
					set acctSuffix to ".imapmbox"
				else if acctType is equal to pop then
					set acctSuffix to ".mbox"
				else
					display dialog "Don't know account type '" & acctType & "'" buttons {"Ok"}
					return
				end if
				set acctFolder to account directory of account of mb
				set msgFolder to "Messages/"
				try
					repeat while class of mb is mailbox
						set mbName to name of mb
						set msgFolder to mbName & acctSuffix & "/" & msgFolder
						set mb to container of mb
					end repeat
				on error errMessage number errNumber
					display dialog "Error: " & errNumber & return & tab & errMessage with title "ERROR" buttons {"Ok"}
				end try
				set msgFile to (id of msg) & ".emlx"
				if msgURLs is not equal to "" then
					set msgURLs to msgURLs & return
				end if
				set msgURLs to msgURLs & "file://" & acctFolder & "/" & msgFolder & msgFile
			end repeat
		end tell
		display dialog msgURLs with title "Message URLs" buttons {doClipBoard, "Cancel"} default button 1 cancel button 2 giving up after 360
		if button returned of result is doClipBoard then
			tell me to set the clipboard to msgURLs
		end if
		
	end perform mail action with messages
	
	-- If run as an ordinary script, instead of directly from the Scripts
	-- menu, it will call the default handler instead.
	on run
		tell application "Mail" to set selectedMessages to selection
		tell me to perform mail action with messages (selectedMessages)
	end run
end using terms from


[ Reply to This | # ]