AppleScript: Save Clipboard to Text File

This AppleScript will open a "Save as" dialog, which lets you specify a folder and filename, using the folder of the front-most Finder window as the default folder. It will then save the (text) contents of your clipboard to that .txt file.

tell application "Finder"
	if (count of windows) > 0 then
		set theDefault to the POSIX path of ((folder of window 1) as alias)
	else
		set theDefault to path to desktop
	end if
end tell

set resultFile to (choose file name with prompt "Save As File" default name "paste.txt" default location theDefault) as text
if resultFile does not end with ".txt" then set resultFile to resultFile & ".txt"
set resultFilePosix to quoted form of the POSIX path of resultFile
do shell script "pbpaste > " & resultFilePosix

AppleScript to open a new Safari window directly to the compose page in FastMail

Sometimes I like to be able to write an email without seeing the new messages in my inbox. This AppleScript (triggered with LaunchBar of course) solves this problem. It opens a new Safari window directly to FastMail's compose page.

Because FastMail loads so quickly and Safari is generally pretty fast fast, this is essentially the same speed of LaunchBar's "Compose Email" action for Mail.app.

tell application "Safari"
	make new document with properties {URL:"https://www.fastmail.com/mail/compose?u=FILL_IN_FROM_FASTMAIL_URL"}
        activate
end tell

Mail.app: Get URL for selected message with AppleScript and TextExpander

I often use message://<message-id@example.com> URLs to reference a specific email in OmniFocus or Evernote: clicking one of these URLs will automatically open up the source message in Mail.app.

There's not a great way to get these very handy message URLs without AppleScript, so based on this SuperUser answer, I created a TextExpander snippet.

Now, when I type xmsg, TextExpander will insert the message URL for the selected message in Mail.app into whatever application I'm working in.

Here's the TextExpander snippet, and here's the AppleScript:

tell application "Mail"
	set selectedMessages to selection
	set theMessage to item 1 of selectedMessages
	set messageid to message id of theMessage
	-- Make URL (must use URL-encoded values for "<" and ">")
	set urlText to "message://" & "%3c" & messageid & "%3e"
	return urlText
end tell