Why does it take time to run a Mail applescript?
  • I've noticed that every time I run a Mail applescript there is a 3-5 second delay before something actually happens in Mail. The next time I run the script everything happens at once, then if I wait for awhile I'm back to the delay. This happens on Snow Leopard and Leopard.

    I think this is Mail thing but if you have any hint/tips


    The script:

    tell application "Mail" to activate
    tell application "System Events"
    tell process "Mail"
    tell menu bar 1
    click menu bar item "Message"'s menu "Message"'s ¬
    menu item "Reply"
    end tell
    delay 0.5
    key code 117 -- Forward Delete
    key code 125 using command down -- down arrow
    key code 36 -- Return
    end tell
    end tell
  • Hi jem - I'm guessing it probably means that the system has "paged out" parts of Mail's code from memory, to make room for other stuff. When you run the script, it forces the system to load all the required code back into memory, so it's there when you run it again.

    I'm guessing if you did nothing but hang out in Mail all the time, it would probably not happen and you wouldn't see the delay. But as you go about your system working on other stuff it probably causes Mail's code to get deprioritized.
  • Yes, that's probably the cause.
  • I know this thread is old, but I'm still experiencing this issue, and I'm not sure that's actually the cause. I can go to Mail and click the Reply button in the toolbar, and I get an immediate response. Immediately after that, I hit Command-R to trigger FastScripts, and there's a delay. If I trigger FS right after that, it's quick.

    So I think what's happening is that FS is being paged out, not Mail. Or perhaps it's part of AppleScript that's being paged out. In any case, is there anything that can be done? I know it's not really your responsibility to fix virtual memory issues, but if you have any ideas, I'd appreciate it.

    Thanks.
  • It does seem possible that it is stuff in FastScripts itself being paged out. Possibly in a future update I could look into whether it makes sense to advise the system not to page out certain parts of FastScripts, or the scripts in memory. I'm not sure exactly what the options are there, and I'd be a little afraid that by trying to fix this one problem I might cause other performance problems.
Start a New Discussion

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!