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 FILE

set 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.5

set 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.1

set 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 1

end 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)


activate

end 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)

Posted on Oct 29, 2018 12:10 PM

Reply
Question marked as Top-ranking reply

Posted on Oct 30, 2018 7:02 AM

I found a simple solution in combining all the script files into one. It was a matter of me formatting the if else statement incorrectly at first try.



-- HANDLER, LIST

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


-- LISTS

set RepList to {"four", "five", "six", "seven"}

set EmailList to {"four@xxxxx.com", "five@xxxxx.com", "six@xxxxx.com", "seven@xxxxx.com"}

set WorkflowList to {"Proof", "Order", "Cancel"}


--Dialog

set emailProcess to button returned of (display dialog "Choose Email Process." buttonsWorkflowList)


--Conditions, PROOF

if emailProcess = "Proof" then

set Chosen to (choose from list the RepListwith prompt "Choose Rep")

set RepName to (Chosen as string)

set Email to item (list_position((Chosen as string), RepList)) of the EmailList



-- Proof Auto Select Attachment & Subject Name

tell application "Finder"


activate


delay 0.1

set theFile to selection as text

set SubjectName to name of (theFile as alias)

set theFile to selection as text

end tell



-- Proof Email Settings

tell application "Mail"


activate


delay 0.1

set 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 1

end tell



--Conditions, ORDER

else if emailProcess = "Order" then



-- Order Auto Select Attachment & Subject Name

tell application "Finder"


activate

set 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



-- Order Email Settings

tell application "Mail"


activate


delay 0.5

set 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

end if


Similar questions

1 reply
Question marked as Top-ranking reply

Oct 30, 2018 7:02 AM in response to chezarey

I found a simple solution in combining all the script files into one. It was a matter of me formatting the if else statement incorrectly at first try.



-- HANDLER, LIST

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


-- LISTS

set RepList to {"four", "five", "six", "seven"}

set EmailList to {"four@xxxxx.com", "five@xxxxx.com", "six@xxxxx.com", "seven@xxxxx.com"}

set WorkflowList to {"Proof", "Order", "Cancel"}


--Dialog

set emailProcess to button returned of (display dialog "Choose Email Process." buttonsWorkflowList)


--Conditions, PROOF

if emailProcess = "Proof" then

set Chosen to (choose from list the RepListwith prompt "Choose Rep")

set RepName to (Chosen as string)

set Email to item (list_position((Chosen as string), RepList)) of the EmailList



-- Proof Auto Select Attachment & Subject Name

tell application "Finder"


activate


delay 0.1

set theFile to selection as text

set SubjectName to name of (theFile as alias)

set theFile to selection as text

end tell



-- Proof Email Settings

tell application "Mail"


activate


delay 0.1

set 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 1

end tell



--Conditions, ORDER

else if emailProcess = "Order" then



-- Order Auto Select Attachment & Subject Name

tell application "Finder"


activate

set 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



-- Order Email Settings

tell application "Mail"


activate


delay 0.5

set 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

end if


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

applescript list prompt to front

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.