I've got the following AppleScript (below). I'm attempting to confirm the sending of an email. This AppleScript is already successfully hooked up to an "outbox rule" (using Mail Act-On) in Mail.app, and I've verified that it runs when it is supposed to (at the time of sending).
The ultimate goal is to pop a dialog to the user, asking if they "really" want to send the email. If not, stop the email from being sent.
The current script attempts to delete the message, but that doesn't work. Any ideas?
using terms from application "Mail"
on perform mail action with messages messageList for rule theRule
repeat with thisMessage in messageList
set theResult to display dialog "Send?" buttons {"OK", "Cancel"} default button 2
if button returned of theResult is not equal to "OK" then
delete thisMessage
end if
end repeat
end perform mail action with messages
end using terms from
I think that a "Cancel" button in a display dialog will immediately end execution of your script which means that the delete thisMessage line never is run.
You might try changing that to something like:
set theResult to display dialog "Send?" buttons {"OK", "No, Delete Message"} default button 2
if button returned of theResult is not equal to "OK" then
...
Related
There I have an issue hope so I will get the right answer here. I have an real estate business. I am using the outlook calendar to book the meetings. but when I am assigning the time to the user or doing any edit-related operation that time another user is getting the mail alerts.i want to disable those I only want to send those the appointment mail noting else. is there any way to disable those emails?
The Application.ItemSend event is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem, is used in a program. So, if you need to prevent anything from sending out, you can set the Cancel parameter to false, for example, a VBA handler is shown below:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
prompt = "Are you sure you want to send " & Item.Subject & "?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
Cancel = True
End If
End Sub
My VBScript is running in system account I need a Confirmation Message Box With Yes/no option to popup and be visible to user. I am able to display the message box using this command
ObjShell.run "cmd.exe /C "" MSG * /SERVER:" &IP& " " &Str_Message &""&""""
but I need yes and no confirmation box and fetch user Choice there.
Here is the documentation on the MsgBox function.
Here's an example of that code. These constants are built into vbscript, so you don't need to declare them. The vbSystemModal value will cause the message box to be "modal" - as in, it will appear on top of all other windows until it is dismissed.
userInput = MsgBox("Prompt",vbExclamation+vbYesNo+vbSystemModal,"Title")
Select Case userInput
Case vbYes
MsgBox "User pressed yes."
Case vbNo
MsgBox "User pressed no."
End Select
Note that you might want to be careful with an unexpected popup to end users, especially as it relates to which button is default and if the dialog is modal. If a user is typing and they hit spacebar when the box pops up, they might select the default button without reading the message first. You might consider the vbDefaultButton1 or vbDefaultButton2 values to assign a default button.
I have the following AppleScript triggered by a Mail.app rule:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with msg in theMessages
set theText to subject of msg & return & content of msg & date sent of msg
display dialog (theText)
end repeat
end perform mail action with messages
end using terms from
If I select a message, right click and choose 'Apply Rules' it works properly. However, if the script is triggered by an incoming message, it seems to have a random message in theMessages.
Here is the rule:
How do I get the right message?
I'm using High Sierra with Mail 11.2.
As your script will iterate over your mail, I expect that your messages are not sorted by date ... So when you run you script it will take the first element (and not the most recent)
Could you run Mail, then sort your email by date (with the most recent at top position) then quit and re-run Mail (to double-check that configuration was saved)
Then verify if your script works.
If you don't want to set the filter manually, according to this, you may add at the following script to the beginning :
tell application "System Events" to click menu item "Date" of menu "Sort By" of menu item "Sort By" of menu "View" of menu bar item "View" of menu bar 1 of process "Mail"
to sort email by date before running your script in order to get the right message.
You may also take a look here, here and here to verify and double check that the rules are properly setup.
Apparently, handling incoming messages with rules is an asynchronous process. When on perform mail action is called, the message is not yet completely updated. Only partial data is available immediately.
A possible workaround would be to add a delay 1 into the script. This give Mail a second to finish updating the message. Here is what the script then looks like:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with msg in theMessages
-- delay a bit of time for msg to load
delay 1
set theText to subject of msg & return & content of msg & date sent of msg
— do other processing
end repeat
end perform mail action with messages
end using terms from
set var to "Which Application would you like to open?"
display dialog var buttons {"Cancel", "Safari", "Calculator"}
if button returned of result is "Calculator" then
display dialog "Are you sure?" buttons {"No", "Yes"} default button 2
if button returned of result is "Yes" then
tell application "Mail" to activate
end if
else
display dialog "Are you sure?" buttons {"No", "Yes"} default button 2
if button returned of result is "Yes" then
tell application "Safari" to activate
end if
if button returned of result is "Cancel" then
return
end if
end if
result only refers to the line above it. You need to store it as another variable if you wanna use it later.
set TheResult to button returned of result
You should probably try and format your code in this forum a little better to assist people trying to help you. You don't need the last "Cancel" option and you also are asking the user if they want to launch "Calculator" but then you launch "Mail". I've made some modifications to your code and reposted it.
set var to "Which Application would you like to open?"
display dialog var buttons {"Cancel", "Safari", "Calculator"}
if button returned of result is "Calculator" then
display dialog "Are you sure?" buttons {"No", "Yes"} default button 2
if button returned of result is "Yes" then
tell application "Calculator" to activate
end if
else
display dialog "Are you sure?" buttons {"No", "Yes"} default button 2
if button returned of result is "Yes" then
tell application "Safari" to activate
end if
end if
I have been playing with applescript for a while and i am making a text version of pokemon. I have a choose from list and a if statement to start a display dialog. when you press Run it should say "You cannot run from a trainer battle" but the display dialog never opens. I can't see what is wrong. I have been searching google but can't find a solution
here is the code
set userStarter to "undefined"
set starterHP to "undefined"
set starterLV to 5
set starters to {"Charmander", "Bulbasor", "Squirtle", "Pikachu"}
set userName to "undefined"
on battle(traner)
display dialog traner & " wants to battle!" buttons {"Next"}
set battleMenu to {"Attack", "Bag", "Run"}
set temp to {choose from list battleMenu}
if temp is "Run" then
display dialog "You cannot run from a trainer battle" buttons {"Ok"}
end if
end battle
display dialog "Welcome to text based Pokemon!" buttons {"Play", "Quit"}
if the button returned of the result is "Play" then
set temp to display dialog "What is your name?" default answer "Ash" buttons {"Submit"}
set userName to text returned of temp
set userStarter to {choose from list starters}
display dialog "Oak: Okay " & userName & " here is your " & userStarter buttons {"Next"}
display dialog "Gary: Hey, lets battle!" buttons {"Battle"}
battle("Gary")
end if
here is the log
tell application "AppleScript Editor"
display dialog "Welcome to text based Pokemon!" buttons {"Play", "Quit"}
--> {button returned:"Play"}
display dialog "What is your name?" default answer "Ash" buttons {"Submit"}
--> {text returned:"Ash", button returned:"Submit"}
choose from list {"Charmander", "Bulbasor", "Squirtle", "Pikachu"}
--> {"Pikachu"}
display dialog "Oak: Okay Ash here is your Pikachu" buttons {"Next"}
--> {button returned:"Next"}
display dialog "Gary: Hey, lets battle!" buttons {"Battle"}
--> {button returned:"Battle"}
display dialog "Gary wants to battle!" buttons {"Next"}
--> {button returned:"Next"}
choose from list {"Attack", "Bag", "Run"}
--> {"Run"}
end tell
Okay, I found the problem.
This line is wrong, remove the { }: (otherwise you are pushing the return of the choose from list into a list, the return is already a list)
set temp to {choose from list battleMenu}
Then choose from lists returns a list so you have to check so:
if temp is {"Run"} then
display dialog "You cannot run from a trainer battle" buttons {"Ok"}
end if
(But if you want to show up the dialog if you press bag you should replace "Run" with "Bag")
The complete code is then:
set battleMenu to {"Attack", "Bag", "Run"}
set temp to choose from list battleMenu
if temp is {"Run"} then
display dialog "You cannot run from a trainer battle" buttons {"Ok"}
end if