Send PDFs from Skim to Gmail


As a follow-up to my Applescript for sending all open PDFs to Papers, here's a script that sends the currently open PDF as an email attachment to a specified address, with a prefixed subject (so you can set up a mail filter to add a label once it arrives). This is particularly useful if you decide you want to have the current PDF available for reference in Gmail on your phone.

Ideally you'd be able to use Google's Documents API to upload the file directly to Google Docs, but the API doesn't have support for PDFs, yet.

Download the script← (edit the sender and recipient as appropriate, then place in ~/Library/Scripts/Applications/Skim).

You can remove all the GrowlHelperApp-related lines if you don't want notification.

set recipientEmail to "" -- edit this
set senderEmail to "" -- edit this
set subjectPrefix to "[pdf] " -- edit this if you like
set notificationsList to {"Sending Mail", "Sent Mail"}
tell application "Skim"
	set thisDoc to document of window 1
	set docFile to POSIX path of (file of thisDoc as string)
	set docTitle to name of thisDoc
	set docText to text of thisDoc
	tell application "GrowlHelperApp"
		register as application "Skim Gmailer" all notifications notificationsList default notifications notificationsList icon of application "Skim"
		notify with name "Sending Mail" title "Sending " & docFile description docTitle application name "Skim Gmailer"
	end tell
	tell application "Mail"
		set newMessage to make new outgoing message with properties {subject:subjectPrefix & docTitle, content:docText}
		tell newMessage
			set sender to senderEmail
			make new to recipient at beginning of to recipients with properties {address:recipientEmail}
			tell content to make new attachment with properties {file name:docFile as string} at after the last word of the last paragraph
		end tell
		send newMessage
	end tell
	tell application "GrowlHelperApp" to notify with name "Sent Mail" title "Mailed " & docFile description docTitle application name "Skim Gmailer" with sticky
end tell