Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I didn't test this but it should do what you need... at least it shows you the proper approach. You basically use a "property" to keep track of some value from the last time the script was run. In this case we check for the name of the frontmost window and see if it matches your criteria. If the window name doesn't do what you need then just find some other value to track between launches of the script. The basic approach should work.</p> <p>EDIT: using the ID of the message, which is unique, the following will do what you want:</p> <pre><code>property lastWindowID : missing value tell application "Mail" set windowIDs to id of windows if windowIDs does not contain lastWindowID then set newMessage to make new outgoing message with properties {subject:"some subject", content:"" &amp; return &amp; return} tell newMessage set visible to true make new to recipient at end of to recipients with properties {name:"some name", address:"some address"} end tell activate set lastWindowID to id of window 1 else tell window id lastWindowID set visible to false set visible to true end tell activate end if end tell </code></pre> <p>the visibility toggle seems to be the only way to get the window in front, as <code>frontmost</code> is a read-only property. The <em>lastWindowID</em> property will store the ID as long as the script is not re-compiled (<em>caveat empteor</em>: do not put this into an Automator service, as these get re-compiled every time the service is loaded).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload