How to run custom AppleScript in the background at all times? Given an AppleScript file designed to poll for an application dialog box every 30 seconds, how can I easily setup my Mac OS so that this AppleScript file starts every time I login silently in the background?

Code for the script ( in case interested ) is listed below, and is designed to click "Later" on the AirMail Beta app:

repeat
    if (exists application "AirMail Beta") then
        tell application "System Events" to tell process "Airmail Beta"
            if exists (button "Later" of front window) then
                click (button "Later" of front window)
            end if
        end tell
    end if
    delay 30
end repeat


The above script works, but if anyone can think of a better way to auto-click a dialog without writing an AppleScript that polls every few seconds, feel free to offer such a solution in comments.  Mainly though, I'd like to know the best way to manage AppleScripts designed to run continuously so they can be enabled / disabled and startup without being seen at login automatically.
In my opinion, the best way to do it is by using Apple's own task scheduler: launchd, because you don't need to install third-party software. First, the theory: to run a script from the command line, you just run: 

osascript /PATH/TO/YOUR/script.scpt


Knowing this, all you have to do is create a plist file in ~/Library/LaunchAgents/ with this:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;air-mail-beta.job&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/usr/bin/osascript&lt;/string&gt;
        &lt;string&gt;/PATH/TO/YOUR/SCRIPT&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;


The name of the plist file doesn't matter, but it should be in ~/Library/LaunchAgents/. Also, make sure to change /PATH/TO/YOUR/SCRIPT accordingly.

Finally, you just need to tell launchd that you want this script to always run. To do that, you just do: 

launchctl load -w ~/Library/LaunchAgents/NAME-OF-YOUR-PLIST.plist


and you're done! If it looks like the script didn't start, you can do this: 

 launchctl start air-mail-beta.job


where air-mail-beta.job is the property under &lt;key&gt;label&lt;/key&gt; that we've set in the plist file.

Finally, should you ever need to disable the script, don't forget to unload it with: 

launchctl unload -w ~/Library/LaunchAgents/NAME-OF-YOUR-PLIST.plist


I know this solution is more technical, but trust me, that's a better way to deal with your issue. If you have any question, just ask!