Select a file in Finder and email it automatically

Getting set up

Service receives selected ‘files or folders’ in ‘any application’

Step 1

Step 2

Step 3

on run {input, parameters} 
set emailTo to (item 1 of input as text)
set myEmail to "myemail@example.com" -- Enter your email here
tell application "Finder"
set theFile to the selection -- Get selected file in finder
set fileName to name of (info for (selection) as alias) -- Get file name for use in subject line
end tell
set currentDate to date string of (current date) -- Get current date to use in subject line
set theSubject to "File: "& fileName & "| Current date: "& currentDate
set theBody to "Hi, here you go!"
set theAddress to emailTo
set theSender to "myEmail"
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
tell theNewMessage
set visibile to false
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress} -- This adds the file
try
make
new attachment with properties {file name:(theFile as alias)} at after the last paragraph
set message_attachment to 0
log "message_attachment = "& message_attachment
on error
set
message_attachment to 1
end try

delay
1 -- Delay necessary for attachment to attach
send theNewMessage
end tell
end
tell
return input
end run
set emailTo to (item 1 of input as text)
{file name:(theFile as alias)}
delay 1

Step 4

Bonus Option 1 — Keyboard shortcut

  • Go to System Preferences
  • Go to Keyboard > Shortcuts
  • Select Services on the left and scroll to the Files and Folders dropdown
  • Find the name of your service and on the right, it will say ‘none’
  • Click on ‘none’ and hit the keys you’d like to use as a command. I use shift + cmd + e.

Bonus Option 2 — Email multiple selected files

set theFiles to selection as list
set fileName to name of first item of theFiles
tell theNewMessage
set visibile to false
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress} -- This adds the file
repeat with aFile in theFiles
make
new attachment with properties {file name:(aFile as alias)} at after the last paragraph
end repeat

delay
1 -- Delay necessary for attachment to attach
send theNewMessage
end tell

Bonus Option 3— type an arbitrary string and let the program decide the recipient

set theName to (item 1 of input)
if (theName = "amy") then
set emailTo to "amy@gmail.com"
else if (theName = “john”) then
set emailTo to "john@gmail.com"
else
display dialog “Could not match an email”
return
end if

Bonus Option 4— Use a popup to select a recipient

Bonus Option 5— Email multiple recipients

If this helped you out, please hit that little heart down below!

Owner at Moisaconsulting.com. I do everything I can, as fast as I can, with as little money as possible.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Azure Function Architecture (HTTP Trigger)

Part 2: Why we are building Spool and why you should care

Meme: “Billy it’s time to learn about money and the importance of your own investment strategy.” Billy puts his money into someone else’s strategy. “Billy wait!”

D3 Step-by-step Guide — (Part 4 of 4) Singapore HDB Resale Price on Planning Map — GitHub Pages

@KnitFinance is pleased to announce its partnership with @SolHub_Finance . 🔥🔥

{UPDATE} Ténis, descobrir quem é o famoso jogador de tênis, fotos questionário Hack Free Resources…

Perspective Transformation with Kornia

Community Update

Flutter : Shared Element Transitions — Hero — Heroes

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adam Moisa

Adam Moisa

Owner at Moisaconsulting.com. I do everything I can, as fast as I can, with as little money as possible.

More from Medium

5 awesome photo spots in the Salzburger Seenland

Sourcetree Command Line Tools “Installation failed” Quick Fix

How to Gain Pitching Velocity: A Beginners Guide To Training Part 1

TOOLS FOR SONGWRITING ESSENTIALS