applescript list prompt to front
Hoping someone can give me some Applescript help. I am new and teaching myself so this may be sloppy.
I have 3 total application files I made with Applescript. Originally, I created two scripts for two different email processes. Brief description:
Script 1 (Order) - takes a selected PDF file, attaches it to an email with subject, CC, and recipient information.
Script 2 (Proof) - creates a prompt (select email recipient), attaches selected PDF file to new email with subject, content, and recipient information.
I decided to try to make these two different script applications into one application for convenience.
Script 3 "Email" - creates a prompt (Order, Proof) which calls to run one of the previous scripts.
When I run my Email script application and select "Proof" my second prompt does not show at the front. Is there a way to fix this? I would love to have all these scripts in one file, but I cannot find a way to add an entire script inside of an if statement. Scripts below.
"Order"
tell application "Finder"
activate
--SET SUBJECT NAME FROM SELECTED FILEset theFile to selection as text
set TheName to name of (theFile as alias)
set Job to ((characters 1 thru -12 of TheName) as string)
set SubjectName to (Job & "(to order)")
set theFile to selection as text
end tell
tell application "Mail"
activate
delay 0.5set theAddress to "one@xxxxx.com" -- the receiver
set theCc1 to {"two@xxxxx.com"}
set theCc2 to {"three@xxxxx.com"}
set theSubject to SubjectName
set theAttachment to theFile
set theMessage to makenewoutgoing messagewith properties {subject:theSubject}
tell theMessage to makenewto recipientwith properties {address:theAddress}
tell theMessage to makenewcc recipientwith properties {address:theCc1}
tell theMessage to makenewcc recipientwith properties {address:theCc2}
tell theMessage to makenewattachmentwith properties {file name:theAttachment as alias} at front
end tell
"Proof"
--SET PROMPT BOX
on list_position(this_item, this_list)
repeat with i from 1 to the count of this_list
if itemi of this_list is this_item then return i
end repeat
return 0
end list_position
set the SalesRep to {"four", "five", "six", "seven"}
set the RepEmail to {"four@xxxxx.com", "five@xxxxx.com", "six@xxxxx.com", "seven@xxxxx.com"}
tell application "System Events" to activate (choose from list the SalesRepwith prompt "Choose Sales Rep:")
set the chosen_person to the result
if the chosen_person is false then return "user cancelled"
set the RepName to (chosen_person as string)
set the Email to item (list_position((chosen_person as string), SalesRep)) of the RepEmail
--SELECT FILE
tell application "Finder"
activate
delay 0.1--SET SUBJECT NAME FROM SELECTED FILE
set theFile to selection as text
set SubjectName to name of (theFile as alias)
set theFile to selection as text
end tell
tell application "Mail"
activate
delay 0.1set theSubject to SubjectName
set theAttachment to theFile
set theContent to "Hi " & RepName & ",
Your proof is attached, below.
"
set theAddress to Email
set theMessage to makenewoutgoing messagewith properties {subject:theSubject, content:theContent}
tell theMessage to makenewto recipientwith properties {address:theAddress}
tell theMessage to makenewattachmentwith properties {file name:theAttachment as alias}
display dialog "Set Signature." buttons {"Ok"} default button 1end tell
"Email"
set jobOrder to {"Order"}
set jobProof to {"Send Proof"}
set jobProcess to {"Proof", "Order"}
on appLauncher(theSelection)
repeat with i from 1 to (count of items in theSelection)
tell application (itemi of theSelection)
activateend tell
end repeat
end appLauncher
set theSelection to choose from listjobProcesswith title "Job Process"
if theSelection is false then
error number -128
else
set theSelection to item 1 of theSelection
if theSelection = (item 1 of jobProcess) then
appLauncher(jobProof)
else if theSelection = (item 2 of jobProcess) then
appLauncher(jobOrder)else
return
end if
end if
OS X El Capitan (10.11.6)