Calling AppleScript handler from tell block - applescript

I'm trying to call a function/handler from a tell block, but AppleScript keeps throwing an error:
Result: error "AppleEvent handler failed." number -10000
The script fails where I'm calling start_varnish():
tell application "System Events"
set iTermIsRunning to exists (processes where name is "iTerm")
end tell
tell application "iTerm"
activate
try
tell current terminal
if iTermIsRunning then
launch session "Default Session"
end if
tell the last session
my start_varnish()
end tell
end tell
on error err
log "Reopening iTerm2"
reopen
tell current terminal
tell the last session
my start_varnish()
end tell
end tell
end try
end tell
on start_varnish()
set name to "Varnish Cache"
end start_varnish
When I move the contents of the handler and place it directly in the code above, it works fine, but I would like to wrap the functionality in a handler for reusability.

The closest fix I could find looks as follows:
tell application "System Events"
set iTermIsRunning to exists (processes where name is "iTerm")
end tell
tell application "iTerm"
activate
try
tell current terminal
if iTermIsRunning then
launch session "Default Session"
end if
my start_varnish()
end tell
on error err
log "Reopening iTerm2"
reopen
my start_varnish()
end try
end tell
on start_varnish()
tell application "iTerm"
tell current terminal
tell the last session
set name to "Varnish Cache"
end tell
end tell
end tell
end start_varnish
I'm not sure if the scoping in my original question for cell current terminal and tell the last session is understood inside the context of the start_varnish() handler.

Related

Using AppleScript to send email with Outlook for Mac no longer works

I have an AppleScript that reads a text file that contains a list of addresses, it then creates a message for each of those address in Outlook with a subject and sends the email automatically. This has been for working for the past year or so but it's no longer working as expected. I'm not sure if this is down a recent update of Outlook or to my Mac OS. What happens now is that it will only send the address on the 1st line in the txt file.
The error message in the Results window is:
error "Can’t get every to recipient of missing value." number -1728 from every «class trcp» of missing value
In the Events window:
tell application "Microsoft Outlook"
read "/Users/******/OneDrive/address.txt" as «class utf8»
end tell
tell current application
read "/Users/******/OneDrive/address.txt" as «class utf8»
end tell
tell application "Microsoft Outlook"
set the clipboard to "abuse#*****"
make new outgoing message with properties {subject:"this is a test"}
make new recipient with properties {email address:{address:"abuse#****"}} at end of every to recipient of outgoing message id 465175
send outgoing message id 465175
set the clipboard to "postmaster#*****"
make new outgoing message with properties {subject:"this is a test"}
Result:
error "Can’t get every to recipient of missing value." number -1728 from every «class trcp» of missing value
In the Replies window:
tell application "Microsoft Outlook"
read "/Users/******/OneDrive/address.txt" as «class utf8»
--> error number -10004
end tell
tell current application
read "/Users/******/OneDrive/address.txt" as «class utf8»
--> "abuse#****
postmaster#****"
end tell
tell application "Microsoft Outlook"
set the clipboard to "abuse#*****"
make new outgoing message with properties {subject:"this is a test"}
--> outgoing message id 465175
make new recipient with properties {email address:{address:"abuse#****"}} at end of every to recipient of outgoing message id 465175
--> to recipient 1 of outgoing message id 465175
send outgoing message id 465175
set the clipboard to "postmaster#*****"
make new outgoing message with properties {subject:"this is a test"}
--> missing value
Result:
error "Can’t get every to recipient of missing value." number -1728 from every «class trcp» of missing value
I noticed when I was looking at the AppleScript library for Outlook that I couldn't find a reference for recipients. I've also tried code from other sources online that was reported as working and testing with a single address directly in the code but I'm still getting a similar error "missing value"
My Outlook is version 16.39 (20071300)
My MacOS is version 10.15.5
Here is the script, I've starred out the username on the mac for privacy;
tell application "Microsoft Outlook"
set srcFile to ("/Users/******/OneDrive/address.txt") as text
set lns to paragraphs of (read srcFile as «class utf8»)
repeat with ln in lns
set the clipboard to ln
set theMessage to make new outgoing message with properties {subject:"this is a test"}
make new recipient with properties {email address:{address:ln}} at end of to recipients of theMessage
send theMessage
end repeat
end tell
Can anyone help?
I can confirm that my send mail bug is fixed with Outlook 16.41 (20072700) Insider Fast Release
Hi I have a similar problem since office update 16.39, the previous office version 16.38 works fine.
This scripts works only one time if outlook mac is closed. After the second try without closing outlook again it produces an error:
tell application "Microsoft Outlook"
set theMessage to make new outgoing message with properties {sender:{name:"My Name", address:"demo#demo.com"}, subject:"test", plain text content:"Hallo"}
tell theMessage
make new to recipient with properties {email address:{address:"test#test.com"}}
end tell
send theMessage
end tell
Ergebnis:
error "missing value versteht die Nachricht „make“ nicht." number -1708 from missing value
translated: "Missing value doesn't understand the make message" or
"Missing value doesn't understand the make event"
Gary,
please file a bug report. Description is in this thread
https://answers.microsoft.com/en-us/msoffice/forum/all/applescript-outlook-send-mail-stops-working-with/c7e63696-0a71-4e68-9764-f7e7794b92fd

Setting message signature of outgoing message using AppleScript

Since I installed Sierra I can't get a piece of AppleScript working which worked before.
I'm trying to create a message (in Apple Mail) with a signature, but keep getting errors.
I used to create/fill the message like this:
set msg to make new outgoing message with properties {content:messageContent}
set message signature of msg to signature "X"
Before Sierra this worked perfect, now I'm getting an error saying: Mail got an error: AppleEvent handler failed.
So I tried several things and ended up (using AppleScript dictionaries) with:
set msg to make new outgoing message with properties {content:messageContent, message signature:signature "X"}
Which ends up in an error saying: Mail got an error: Can’t make class outgoing message.
Anyone who can help me out on this one?
This is a known bug. I had the same issue.
You also failed to mention that this is for Mail in your original reply. Might want to include the application in future posts!
I was having the same problem and came across a working solution. The "button 3" used to be "button 2" until I upgraded to Sierra 10.12.4 this past weekend.
Keystroke "F", is just the first letter of my signature name. Modify that as you wish.
try
set message signature of theMessage to signature "your signature name"
on error
tell application "Mail" to activate
tell application "System Events"
tell process "Mail"
click pop up button 3 of window 1
delay 0.01
keystroke "F"
delay 0.01
keystroke return
delay 0.01
end tell
end tell
end try

Why do I keep getting an error on this short applescript

tell application "System Events"
tell security preferences
get properties
end tell
end tell
The script editor gives the error "System Events got an error: AppleEvent handler failed." number -10000
Because there is no properties property in secure preferences object.
The available properties are:
automatic login
log out when inactive
log out when inactive interval
require password to unlock
require password to wake
secure virtual memory (returns an error, seems to be a bug)
Read a property directly for example
tell application "System Events"
tell security preferences
get automatic login
end tell
end tell

How to run applescript until message is received

I want to run an applescript script from the command line, and have a loop in it run until the a message is received. I'm updating a variable when a message is received using this:
using terms from application "Messages"
on message received theMessage from targetBuddy
set gotMessage to true
end message received
end using terms from
However, when I place this inside the on run block, I get an error at on message received saying "Expected “end” but found “on”." And when I place it outside the run block the script can be saved and will run, but the on message received handler isn't being called, which I checked by throwing a log statement in there. How can I get the script to check for a message being received while also running another loop?
You cannot run application event handlers outside the application because the event handler needs a target process with an AppleScript scripting definition (dictionary) to register the events and send the apple event to.

Openbravo: Add a field to a window

I am trying to add a field following the HowTo in the documentation with no errors in the process.
The problem comes when I think I am done, I visit Multiphase Project page and it does not load and shows this error:
Error occured: freemarker.template.TemplateModelException: get(tabView) failed on instance of org.openbravo.client.application.window.StandardWindowComponent
I have tried to repeat the HowTo but I couldn't find where I might be getting it wrong.
In the "Reports and Processes" window, where you created the process check whether "Manual.." is checked.. if not then check it.
run "ant smartbuild -Dtr=no"
Do not forget to comment whether this works or does not work...

Resources