Applescript to wait for AppleMail to download messages. - osx-lion

Prior to 10.7.x this AppleScript used to work with AppleMail:
tell application "Mail"
activate
check for new mail
repeat until (background activity count) = 0
do shell script "sleep 1"
end repeat
end tell
However, since 10.7.x+ this does not seem to work anymore. It doesn't even go in to the repeat loop. My guess is that AppleMail has changed the way it downloads emails and doesn't use "background activity" anymore.
Anyone know how to wait for all emails to download in AppleMail 5+ with AppleScript?

I checked on 10.8.2 and it worked. Maybe the check is really fast on your system and it's already finished when the repeat until condition is evaluated. But I can't understand what's the objective of the script. Also, it would be better if you replace the do shell script "sleep 1" with a simpler delay 1.

Related

Launch on event with python

here I write my first question as programming beginner starting with python.
I have a small script that executes a loop, which function is to download a list from the server, compare it with other lists and see if something has happened. Usually the answer is NO, but sometimes something happens. When the answer becomes YES, I would like this script at this point to be able to "launch the second program", a similar script that from here takes care of the instructions to handle the specific event signaled while the " main program "continues to interrogate the server and compare the answers (that's the only thing he has to do).
considering that you can run it with two clicks from the desktop specifying only one variable (that comes from the first script), I thought it was easy to "trigger" the execution of a python file in a new window or something like that ...can anybody tell me how I can make it start at the request of the first script avoiding that the first script remains blocked waiting for answers and continues to execute its cycle?

Add Operation to File Menu in an Applescript Application

I have an application that was made with applescript for now I can substitute this for the code:
try
tell application "System Events"
delay 10
display dialog "blah blah"
end tell
end try
and I would like the user to be able to quit this application by either rick clicking on it and selecting "Quit" or by going to File>Quit. But I believe the try is catching the quit. Is there any way to do this?
You can't do what you ask. Even if possible, the delay statement stops everything for 10 seconds so it can't catch any "quit" actions. If you explain a little more about what you're trying to do then there may be another way to accomplish your goal.
Note also that in Yosemite the delay command isn't working properly. It's a bug. You can use this instead until the bug is fixed.
do shell script "sleep 10"

Run a program while another program is active (Autohotkey)

I was wondering if i could get AHK-script to automatically launch a program in the background when i start another.
Example:
Execute C:\any.exe.
AHK launches: C:\monitor.exe
When any.exe is closed, ahk should kill monitor.exe
Awsome if you guys could help me.
Edit: Note that i am a complete newcomer to programming or scripting in every way you can think of
Check out timer in the autohotkey docs.
You could set a timer that checks every 5 seconds to run winexist to test for the existence of c:\any.exe - and when it returns true then your code could run c:\monitor.exe
Now that your code knows that c:\any.exe is running, your code could launch a second timer that checks for when its process is closed (check out process in the ahk docs). When it is closed, then use winkill to close the c:\monitor.exe process.
So, look up these commands:
winexist
timer
process

Run a program automatically on script start-up

I am trying to make an AHK script open another program everytime it is started. The problem is, I don't want this to happen if that other program is already opened.
Here's what seems to be supposed to be working, but isn't : (this section is placed at the very top of my script)
SetTitleMatchMode, 2
#IfWinNotExist, Microsoft Excel - myExcelFile.xls
Run C:\myExcelFile.xls
#IfWinExist
;REST OF MY SCRIPT GOES HERE
What should be happening :
If the window "Microsoft Excel - myExcelFile.xls" is not opened, run it. If not, do not.
What is happening :
Whether it is opened or not, it will try to run it again.
So yeah, even though I had read the documentation, I had understood that the difference between #IfWin and IfWin was whether they were used inside or out of a specific hotkey. To my understanding, "creates context-sensitive hotkeys and hotstrings" also included "context-sensitive auto-execution" (when code is not inside a hotkey)
Indeed I was wrong and the solution is to remove the #.

Precompiled applescript service?

I have created an automator service for my finder which runs an applescript. I will have to use this service incredibly often. I have noticed that after running the service, there is a very large (about ten second) delay before I receive any popups from the script. This is far too long. I am almost positive this delay comes form automator compiling my script every time it is run....
So, I have a question -- is there a way to pre-compile an applescript, then install that applescript as a finder service? Going through automator was the simplest way I could think of to install my script as a service, but if there is a better way -- particularly one that pre compiles my applescript, that would be great.
I'm not sure if it's a "compiled" issue. I see long delays sometimes too, even with compiled scripts. Automator actions are run by the "automator runner" application and applescripts are run by the "applescript runner" application (unless they're created as stand-alone applications). I notice sometimes that during the first launch that it takes extra time but on subsequent launches it acts faster... maybe because the runner applications are up and running during subsequent runs. So I'm more likely to believe it's something in the runner applications rather than the script itself.
However you can run a "compiled" script if you wish. Just create the script as a separate file. Then in the applescript portion of your automator action use this...
run script file "path:to:script.scpt".
With that being said, you can even create the applescript as an application and then run that from automator...
tell application "MyApplescript" to activate
Maybe one of those solutions will help speed it up for you. If you do achieve a speedup, please let us know.