Yes, the variables I’m trying to log are being used every time the script runs so they should be logged. Here’s my script (I imagine Nigel Garvey could reduce this to half its size):
--on open theseItems —(this is going to be a droplet when I finish it)
set theseItems to (choose file with prompt "select a pdf to upload" with multiple selections allowed)
tell application "Finder"
--set up paths to the folders
set homePath to (path to home folder) as text
set bluePath to homePath & "Dropbox: Blue"
set conniePath to homePath & "Dropbox: Connie"
set greenPath to homePath & "Dropbox: Green"
set orangePath to homePath & "Dropbox: Orange"
set pinkPath to homePath & "Dropbox: Pink"
end tell
--set up our teams in outlook
tell application "Microsoft Outlook"
--activate
set blueTeam to get members of group "Blue"
set pinkTeam to get members of group "Pink"
set greenTeam to get members of group "Green"
set orangeTeam to get members of group "Orange"
set connieTeam to {{
|name|:"Connie Root",
address:"
email@hidden"}}
end tell
--enter the customer name for the email subject line
tell me to activate
--choose the folder we're going to upload to
set theTeam to choose from list {"Blue", "Connie", "Green", "Orange", "Pink"} with prompt "Choose the team Dropbox folder"
set teamGroup to "" --initialize teamGroup
if item 1 of theTeam is "Blue" then
set thePath to bluePath
set teamGroup to blueTeam
else if item 1 of theTeam is "Connie" then
set thePath to conniePath
set teamGroup to connieTeam
else if item 1 of theTeam is "Green" then
set thePath to greenPath
set teamGroup to greenTeam
else if item 1 of theTeam is "Orange" then
set thePath to orangePath
set teamGroup to orangeTeam
else if item 1 of theTeam is "Pink" then
set thePath to pinkPath
set teamGroup to pinkTeam
log theTeam —these three variables are being logged the first time I run the script but not on subsequent runs.
log thePath
log teamGroup
end if
set teamCount to count of teamGroup
--now copy the files to the selected dropbox folder
set fileList to {}
set subjectLine to ""
repeat with i from 1 to count of theseItems
tell application "Finder"
set thisItem to item i of theseItems
duplicate file thisItem to thePath
end tell
--grab our file name(s) to put in our email
set fileList to fileList & thisItem
log fileList
set AppleScript's text item delimiters to ":"
set x to item i of fileList
set y to every text item of (x as text)
log y
set fileName to the last text item of y
set item i of fileList to fileName
--grab the customer name to put in subject line
set subjectLine to (text item 4 of y) & " Proof"
set AppleScript's text item delimiters to ""
end repeat
--fileList
delay 3
tell application "Finder"
if exists (thePath as text) & ":" & fileName then
display dialog "File(s) successfully uploaded to Dropbox>"
end if
end tell
--now our email
tell application "Microsoft Outlook"
--compose the message
set a to "The following files are in the "
set b to theTeam
set c to " Dropbox folder: <br>"
set d to ""
repeat with i from 1 to count of fileList
set d to (d & ((item i of fileList as string) & "<br>"))
end repeat
set messageBody to a & b & c & d
log messageBody
--make a new message and add the recipients
set theMessage to make new outgoing message with properties {subject:"THIS IS ONLY A TEST! " & subjectLine, content:messageBody}
repeat with j from 1 to teamCount
make new recipient at theMessage with properties {email address:{name:(name of item j of teamGroup), address:(address of item j of blueTeam)}, type:to recipient type}
end repeat
--send the message and verify that it has been sent
try
send theMessage
on error errmsg number errnum
display dialog "Email was not sent."
end try
delay 3 --to give outlook time to send the message
try
get was sent of theMessage
on error errmsg number errnum
display dialog "Email was successfully sent."
end try
end tell
--end open