Applescript only attaches once and then no longer - applescript

I have an Applescript that attaches a bunch of spams to a reporting email flawlessly ONCE. Then it stops attaching any spams in subsequent runs regardless of whether it's the same batch of spams or another new batch of spams. Even though it stops attaching any spams in subsequent runs, it otherwise runs fine in that it creates the reporting email, addresses it and tacks on the subject line which gives a tally of spams being reported. I have a gut feeling that it's likely an aliasing issue (in that it's looking for the wrong alias and thus can't attach the spam) but I can't quite see how to fix it. I enclose the Applescript below with personal info redacted. Running it under Applescript Editor provides me no errors except for the "--> missing value" (what does this even mean?) after each iteration of the attachment loop. What am I overlooking?
-- User settable constants
set SPAMCOP_ACCOUNT to "REDACTED"
set SENDER_ADDRESS to "REDACTED"
set SPAMCOP_FOLDER_NAME to "SpamCop"
-- Variable initialization
set rawSpamFileList to {} -- List of names of spam files
set spamsProcessed to 0 -- Number of spams processed
set theOutputFolderPath to path to desktop folder -- Desktop folder path
set fullSpamCopFolderPath to (theOutputFolderPath & SPAMCOP_FOLDER_NAME & ":") -- Spam folder on Desktop
tell application "Finder"
-- Create a SpamCop folder on Desktop if there isn't already one
if (exists folder (fullSpamCopFolderPath as string)) = false then
make new folder at theOutputFolderPath with properties {name:SPAMCOP_FOLDER_NAME}
end if
-- Count number of Spams to be processed
set spamsProcessed to number of items of folder (fullSpamCopFolderPath as string)
-- Set the list of names to the raw source folder to loop through
set rawSpamFileList to name of every file of folder (fullSpamCopFolderPath as string)
if (spamsProcessed > 0) then
tell application "Mail"
-- Create a blank spam-reporting email & set sender in it
set spamReport to (make new outgoing message with properties {visible:true, content:" ", sender:SENDER_ADDRESS})
-- Address it and add a tally of junk being reported
tell spamReport
make new to recipient at end of to recipients with properties {address:SPAMCOP_ACCOUNT}
set subject of spamReport to ((spamsProcessed) & " spam(s) being submitted for processing" as string)
set visible to true
-- Attach all the spams in SpamCopFolder as attachment(s) to spamReport.
-- I SUSPECT THE PROBLEM IS IN THE REPEAT LOOP BELOW BUT I CAN'T SEE WHAT'S WRONG!
repeat with thisSpamName in rawSpamFileList
try
set fullSpamPath to ((fullSpamCopFolderPath as string) & thisSpamName) -- Cast fullSpamCopFolderPath alias to string first!
make new attachment with properties {file name:(fullSpamPath as string)} at after the last word of the last paragraph
on error errmsg
display dialog ("Failed with errmsg: " & (errmsg as string)) buttons {"OK"} default button "OK"
end try
end repeat
end tell
end tell
set responseButton to button returned of (display dialog "Clean up SpamCop folder now?" buttons {"Yes", "No"} default button "No")
if responseButton is "Yes" then
delete every item of folder (fullSpamCopFolderPath as string) -- Send spams to trash
else
display dialog "Spam deletion aborted." buttons {"OK"} default button "OK"
end if
else
display dialog "No spam to process! Are you hallucinating?" buttons {"OK"} default button "OK"
end if
end tell
Here is a sample run of 35 spams using the corrected Applescript provide by regulus6633:
tell current application
path to desktop
--> alias "Macintosh HD:Users:username:Desktop:"
end tell
tell application "Finder"
exists folder "Macintosh HD:Users:username:Desktop:SpamCop:"
--> true
count folder "Macintosh HD:Users:username:Desktop:SpamCop:"
--> 35
get name of every file of folder "Macintosh HD:Users:username:Desktop:SpamCop:"
--> {"Spam-20140908064824.eml", "Spam-20140908081508.eml", "Spam-20140908082049.eml", "Spam-20140908082642.eml", "Spam-20140908083224.eml", "Spam-20140908091214.eml", "Spam-20140908091848.eml", "Spam-20140908092708.eml", "Spam-20140908093615.eml", "Spam-20140908093946.eml", "Spam-20140908101749.eml", "Spam-20140908101834.eml", "Spam-20140908102327.eml", "Spam-20140908102809.eml", "Spam-20140908102920.eml", "Spam-20140908103417.eml", "Spam-20140908104041.eml", "Spam-20140908104110.eml", "Spam-20140908112201.eml", "Spam-20140908113458.eml", "Spam-20140908124138.eml", "Spam-20140908124750.eml", "Spam-20140908125605.eml", "Spam-20140908130207.eml", "Spam-20140908130508.eml", "Spam-20140908132133.eml", "Spam-20140908132909.eml", "Spam-20140908134147.eml", "Spam-20140908134736.eml", "Spam-20140908143459.eml", "Spam-20140908143618.eml", "Spam-20140908160051.eml", "Spam-20140908160448.eml", "Spam-20140908173043.eml", "Spam-20140908191450.eml"}
end tell
tell application "Mail"
make new outgoing message with properties {visible:true, content:" ", sender:"REDACTED"}
--> outgoing message id 47
make new to recipient at end of every to recipient of outgoing message id 47 with properties {address:"REDACTED"}
--> to recipient 1 of outgoing message id 47
set subject of outgoing message id 47 to "35 spam(s) being submitted for processing"
set visible of outgoing message id 47 to true
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908064824.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908081508.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908082049.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908082642.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908083224.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908091214.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908091848.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908092708.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908093615.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908093946.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908101749.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908101834.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908102327.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908102809.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908102920.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908103417.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908104041.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908104110.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908112201.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908113458.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908124138.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908124750.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908125605.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908130207.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908130508.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908132133.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908132909.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908134147.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908134736.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908143459.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908143618.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908160051.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908160448.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908173043.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
make new attachment with properties {file name:"Macintosh HD:Users:username:Desktop:SpamCop:Spam-20140908191450.eml"} at after last word of last paragraph of outgoing message id 47
--> missing value
end tell
tell application "AppleScript Editor"
display dialog "Clean up SpamCop folder now?" buttons {"Yes", "No"} default button "No"
--> {button returned:"No"}
display dialog "Spam deletion aborted." buttons {"OK"} default button "OK"
--> {button returned:"OK"}
end tell
Result:
{button returned:"OK"}

I see a mistake here:
set fullSpamCopFolderPath to (theOutputFolderPath & SPAMCOP_FOLDER_NAME & ":")
It should be:
set fullSpamCopFolderPath to (theOutputFolderPath as text & SPAMCOP_FOLDER_NAME & ":")
Notice "as text". You want to add strings and theOutputFolderPath is not a string so you need to make it one before you add the string SPAMCOP_FOLDER_NAME to it.
Here's another error:
set subject of spamReport to ((spamsProcessed) & " spam(s) being submitted for processing" as string)
It should be:
set subject to (spamsProcessed as text) & " spam(s) being submitted for processing"
Again, "spamsProcessed" is a number and you need to make it a string before adding another string to it. Plus you're inside "tell spamReport" and therefore don't need "of spamReport".
Finally, you should move all of your "Mail" code outside the Finder block of code. It doesn't make sense to tell the Finder to tell Mail to do something and it often results in hard-to-find errors when you embed application tell blocks inside of each other.
So try the following. I fixed a few other small errors and removed all of your "as string" stuff because once you fix those errors you don't need it. I didn't try this code but it should work.
-- User settable constants
set SPAMCOP_ACCOUNT to "REDACTED"
set SENDER_ADDRESS to "REDACTED"
set SPAMCOP_FOLDER_NAME to "SpamCop"
-- Variable initialization
set rawSpamFileList to {} -- List of names of spam files
set spamsProcessed to 0 -- Number of spams processed
set theOutputFolderPath to path to desktop folder -- Desktop folder path
set fullSpamCopFolderPath to ((theOutputFolderPath as text) & SPAMCOP_FOLDER_NAME & ":") -- Spam folder on Desktop
tell application "Finder"
-- Create a SpamCop folder on Desktop if there isn't already one
if not (exists folder fullSpamCopFolderPath) then
make new folder at theOutputFolderPath with properties {name:SPAMCOP_FOLDER_NAME}
end if
-- Count number of Spams to be processed
set spamsProcessed to number of items of folder fullSpamCopFolderPath
-- Set the list of names to the raw source folder to loop through
set rawSpamFileList to name of every file of folder fullSpamCopFolderPath
end tell
if (spamsProcessed > 0) then
tell application "Mail"
-- Create a blank spam-reporting email & set sender in it
set spamReport to (make new outgoing message with properties {visible:true, content:" ", sender:SENDER_ADDRESS})
-- Address it and add a tally of junk being reported
tell spamReport
make new to recipient at end of to recipients with properties {address:SPAMCOP_ACCOUNT}
set subject to (spamsProcessed as string) & " spam(s) being submitted for processing"
set visible to true
-- Attach all the spams in SpamCopFolder as attachment(s) to spamReport.
-- I SUSPECT THE PROBLEM IS IN THE REPEAT LOOP BELOW BUT I CAN'T SEE WHAT'S WRONG!
repeat with thisSpamName in rawSpamFileList
try
set fullSpamPath to fullSpamCopFolderPath & thisSpamName
make new attachment with properties {file name:fullSpamPath} at after the last word of the last paragraph
on error errmsg
display dialog ("Failed with errmsg: " & errmsg) buttons {"OK"} default button "OK"
end try
end repeat
end tell
end tell
set responseButton to button returned of (display dialog "Clean up SpamCop folder now?" buttons {"Yes", "No"} default button "No")
if responseButton is "Yes" then
tell application "Finder"
delete every item of folder fullSpamCopFolderPath -- Send spams to trash
end tell
else
display dialog "Spam deletion aborted." buttons {"OK"} default button "OK"
end if
else
display dialog "No spam to process! Are you hallucinating?" buttons {"OK"} default button "OK"
end if

I solved the problem myself. The solution was just to replace this line:
make new attachment with properties {file name:(fullSpamPath as string)} at after the last word of the last paragraph
with this:
make new attachment with properties {file name:fullSpamPath as alias} at after the last word of the last paragraph
As to why the former just worked once or twice and then not again thereafter, I have no idea. Theoretically, the former shouldn't have worked at all. If anybody has any feasible explantion, I'm all ears. But my code now works as expected.

Related

How do I make this AppleScript Folder Watch ignore hidden items?

I have pretty much spent my entire Sunday trying to find an answer to this and I am now admitting defeat and asking for your help. I've read several examples on here and some other AppleScript sites but non of them seem to work when applied to this script. I do however put this down to me.
I'm trying to use the script below to watch a folder then send me an email when a new item has been added and it works just fine. The trouble I am having is getting it to ignore system [or hidden] folders.
I have removed my efforts to do this as they all kept breaking the whole thing, so the version below works but currently it will include hidden items.
property theName : "Name"
property theAddress : "name#company.com"
on adding folder items to this_folder after receiving added_items
set added_Items_List to {}
repeat with oneItem in added_items
set end of added_Items_List to name of (info for oneItem)
end repeat
set {TID, text item delimiters} to {text item delimiters, ", "}
set added_Items_List to added_Items_List as text
set text item delimiters to TID
set dateString to (current date) as string
set theBody to "There are new files in the FTP folder " & name of (info for this_folder) & ":" & return & return & added_Items_List
tell application "Mail"
set newMessage to make new outgoing message with properties {visible:true, subject:"New submissions on FTP: " & dateString, content:theBody}
tell newMessage
make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
end tell
activate
send newMessage
end tell
end adding folder items to
Any help or direction would be much appreciated and hopefully others will benefit from a working solution.
For anyone who come across this post with a similar issue, you may find the answer to your problem on one of these posts.
Applescript System Events Returns .DS_Store - How can I ignore
How to I tell this Applescript to skip some files?
AppleScript : How to get files in folder without hidden files?
Hidden files start with a dot, just filter those items
on adding folder items to this_folder after receiving added_items
set added_Items_List to {}
repeat with oneItem in added_items
set fileName to name of (info for oneItem)
if fileName does not start with "." then
set end of added_Items_List to fileName
end if
end repeat
if (count added_Items_List) = 0 then return
....
But if the Finder on your machine does not show the hidden files by default you don't need the additional lines.

apple scripting with Messages to take action on URL

I'm trying to write an AppleScript for Messages such that if I get a message that contains a URL, the script automatically opens the link in my browser.
I've been able to set a script to run that sends me a notification with the properties of the message, but I've not yet been able to figure out how to take action on the URL.
Here's what I've been able to produce:
using terms from application "Messages"
on message received from theSender for theChat with theContents
display notification theContents as text ¬
with title "New Message from " & theSender
end on message received
end using terms
Here's an example that might help you:
set msg to theContents as text
set AppleScript's text item delimiters to space
set msg to msg as list
repeat with x in items of msg
if "http" is in x then
display dialog x
end if
end repeat

Use Applescript to set the "Reply-To" address

I have a registered domain, and I use hushmail as a mail provider. I'd like to send emails from Mail.app as if they were sent from my domain. The Hushmail SMTP server does not allow me to use a different "from" address than my account name, for security reasons (spam).
I found a way to have Apple mail fill the reply-to mail with a default all the time, here: http://email.about.com/od/macosxmailtips/qt/etalwaysreplyto.htm but that's too drastic for me, as I have multiple mail accounts in my mail client.
In Mail.app, I can set the "Reply to" field manually, but there is no setting in Mail.app to have that automatically filled based on the mailbox I select.
So far, I have an AppleScript which is able to create a reply on the selected mail:
tell application "Mail"
set theSelection to selection
if theSelection is {} then return
activate
repeat with thisMessage in theSelection
set theOutgoingMessage to reply thisMessage with opening window
# Wait for Mail.app to create the reply window
repeat until exists (window 1 whose name = "Re: " & subject of thisMessage)
end repeat
delay 0.1
#
# Here I want to set the reply-to address here based on the
# selected mailbox, or the "from" address of
# the current mail.
#
#
# The I need to restore the cursor to the body of the mail
# (if cursor was moved)
#
end repeat
end tell
I've looked in the AppleScript Dictionary (File -> Open Dictionary -> Mail.app -> Message -> message -> reply to), and this seems to be a property I should be able to set, but when I do something like:
tell theOutgoingMessage
make new recipient at end of reply to with properties {address:"myreplyto#example.com"}
An error pops up saying "Mail got an error: Can't get reply to of outgoing message id 65."
I also tried
tell theOutgoingMessage
set reply to to "myreplyto#example.com"
But that pops up an error saying "Mail got an error: Can’t set reply to of outgoing message id 69 to "myreplyto#example.com".
How can I set the reply-to property of the reply mail I just created?
As I mentioned in the comments to your post, you can't set the reply-to address programmatically because it's a read-only property. Therefore you need to ui script this solution.
The problem with ui scripting is that it's not an exact science. If Apple changes the positioning of the ui elements then your script will stop working. For example, I have Mail.app v6.5 and the reply-to field can be referenced using "text field 1 of scroll area 1 of window 1". In other versions of Mail.app that could be different (and probably is).
Anyway, in v6.5 of Mail.app this will do what you want using ui scripting.
tell application "Mail"
set theSelection to selection
if theSelection is {} then return
activate
repeat with thisMessage in theSelection
set replyToAddress to item 1 of (get email addresses of account of mailbox of thisMessage)
set replyToWindowName to subject of thisMessage
if replyToWindowName does not start with "Re:" then set replyToWindowName to "Re: " & replyToWindowName
-- open the reply message
set theOutgoingMessage to reply thisMessage with opening window
-- Wait for Mail.app to create the reply window
repeat until exists (window 1 whose name is replyToWindowName)
delay 0.2
end repeat
-- make sure the reply-to field is showing
my openReplyToField()
-- set the reply-to address here based on the selected mailbox
my setValueOfReplyToField(replyToAddress)
end repeat
end tell
on openReplyToField()
tell application "System Events"
tell process "Mail"
-- figure out if the reply-to text field is visible
set staticText to value of every static text of window 1
if staticText contains "Reply To:" then return
-- the reply-to field is not visible so we click the menu item
set viewMenu to menu 1 of menu bar item "View" of menu bar 1
set replyToMenuItem to first menu item of viewMenu whose name contains "Reply-To"
click replyToMenuItem
end tell
end tell
end openReplyToField
on setValueOfReplyToField(theValue)
tell application "System Events"
tell process "Mail"
set replyToField to text field 1 of scroll area 1 of window 1
set value of replyToField to theValue
end tell
end tell
end setValueOfReplyToField
Try if this works:
make new recipient at end of to recipients with properties {address:"myreplyto#example.com"}

How do I make a copy of a sent email, to edit and send again

I am using Outlook for Mac 2011 version 14.3.1 on Mac OS X 10.7.5. I want to take a sent email, make a copy, open, edit and send it again. I used to have an applescript to do this but the link to download it no longer appears to function.
I suspect it was something like this.
Select you email in the sent iTems and run the script
tell application "Microsoft Outlook"
set theMessage to item 1 of (get selection) # get the first email message
set subj to subject of theMessage
set recip to (email address of to recipient of theMessage)
set cont to content of theMessage
set newMail to make new outgoing message with properties {subject:subj, content:cont}
repeat with i from 1 to number of items in recip
set this_item to item i of recip
tell newMail to make new recipient at newMail with properties {email address:this_item}
end repeat
open newMail
end tell
The script creates a new message with ALL previous recipients,subject and content.
Then opens it ready for editing

Weird behavior from the results of "Get Link URLs from Webpages" action

I'm building an Automator workflow that parses a Dropbox "gallery" page containing Quicktime video files, and automatically builds "direct-download" links for each of the files. In the end, I want all the links to be generated into the body of a Mail.app message.
Basically, everything works as expected, except for the part where the new links are sent to a new Mail.app message. My problem is that the links are sent to the body of the message without newlines, so they all get concatenated into a single line, like this:
https://dl.dropbox.com/u/149705/stackexchange/20121209/stackexchange_automator_prob2.png
(Mail.app seems to be wrapping the concatenated string on the question-marks)
The oddest thing about this is that if I use a "Copy to Clipboard" action at the end of the workflow (instead of my send-to-Mail Applescript), I get totally different results when I paste the same clipboard contents into TextEdit vs. BBEdit.
The links seem to paste into TextEdit properly. However, the same clipboard, pasted into a plaintext BBEdit document, yields only the first link:
https://dl.dropbox.com/u/149705/stackexchange/20121209/stackexchange_automator_prob5.jpg
What could be causing these 3 entirely different behaviors from the exact same results of the "Get Link URLs" action?
The reason you get that result is it the links start out as a List of strings but are being sent to mail.app as a single string.
You do not need to do anything fancy to fix this just put a return after the link.
I would just use this a single 'Run applescript' Action to do the whole job.
The script gathers only the file DL links. Adds a return on the end and send them to Mail.app.
No other formatting required
on run {input, parameters}
set db_tag to "dl-web.dropbox.com/get"
set myLinks to {}
tell application "Safari"
set thelinkCount to do JavaScript "document.links.length " in document 1
repeat with i from 1 to thelinkCount
set this_link to (do JavaScript "document.links[" & i & "].href" in document 1) as string
if this_link contains db_tag then
--add the link with a carriage return on the end.
copy this_link & return to end of myLinks
end if
end repeat
end tell
tell application "Mail"
activate
make new outgoing message with properties {visible:true, content:"" & myLinks}
end tell
end run
Get rid of all of the other actions and update myPage with your gallery URL.
on run
set myPage to "https://www.dropbox.com/sh/aaaaaaaaaaaaaaa/aaaaaaaaaa"
set myLinks to do shell script "curl " & quoted form of myPage & " | grep -Eo 'https://www.dropbox.com/sh/[^/]*/[^/\"]*/[^\"]*' | sed s'/https:\\/\\/www.dropbox.com\\(.*\\)/https:\\/\\/dl.dropbox.com\\1?dl=1/g'"
tell application "Mail"
activate
make new outgoing message with properties {visible:true, content:"" & myLinks}
end tell
end run
Each application is different, it understand or don't understand the output's format.
Regarding your AppleScript action:
input is an AppleScript list, the coercion from a empty string "" do a single line, because the delimiters is set to "" by default.
To get the desired result, set the delimiters to return or linefeed, like this.
on run {input}
set {oTID, text item delimiters} to {text item delimiters, linefeed}
set tContent to input as text
set text item delimiters to oTID
tell application "Mail"
activate
make new outgoing message with properties {visible:true, content:tContent}
end tell
return input
end run

Resources