I have a Mac running macOS Mojave.
this script sends a mail to multiples user when someone adds a new file in my folder.
How can I add the filename in the mail Subject and the path file in the mail body?
How can I apply this action only when the file extension are .pdf or .doc?
here is my script:
property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.
on adding folder items to this_folder after receiving added_items
try
tell application "Finder"
--get the name of the folder
set the folder_name to the name of this_folder
end tell
-- find out how many new items have been placed in the folder
set the item_count to the number of items in the added_items
--create the alert string
set alert_message to ("Folder Actions Alert:" & return & return) as Unicode text
if the item_count is greater than 1 then
set alert_message to alert_message & (the item_count as text) & " new items have "
else
set alert_message to alert_message & "One new item has "
end if
set recipientName to "New file added"
set recipientAddress to "user1@gmail.com, user2@gmail.com"
set theSubject to "new file" & fileName
set theContent to "¡Hello! new file added: pathName fileName"
tell application "Mail"
##Create the message
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
##Set a recipient
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
##Send the Message
send
end tell
end tell
end try
end adding folder items to
I try many times to use this example, but was impossible:
Applescript to return name of new file added to folder
Thanks so much in advance!
Best Answer
This works for me using the latest version of macOS Mojave.
I made some adjustments for you and added a few items to your code. You may need to adjust a few things to better suit your needs, but for now I think the following code should put you back on the right track:
UPDATE:
In this following version of the updated code, I removed all of the “Display Alert” commands and variables. This version will send an email to you with the names of all of the files and the path of the files. It will also send an email to the addresses of your recipient list, with the name of the files and the path of the files (only if the file extensions are .pdf or .doc)