Run applescript as a service I have the following applescript bundled as .app (using Platypus) and starting on user logon (12.4 MB for each user)

#!/usr/bin/osascript

-- INICIO DAS FUNCOES EXTRAS
set app_path to path to current application
set app_name to get name of me
set myPath to path to me
tell application "Finder" to set myFolder to (container of myPath) as string
set commonScript to load script alias ((myFolder) &amp; "FuncoesExtras.scpt")
-- FIM DAS FUNCOES EXTRAS

set WhiteList to {app_name, "App Store", "iTunes", "FecharProgramas", "Finder", "Mail"}

repeat

    tell application "System Events"
        repeat with this_app in (get processes whose background only is false and windows is {})
            set NomeDoApp to the name of this_app
            if NomeDoApp is not in WhiteList then
                try
                    tell NomeDoApp to quit
                    log_event("App " &amp; NomeDoApp &amp; " encerrado com sucesso", app_name) of commonScript
                on error
                    do shell script "killall " &amp; quoted form of NomeDoApp
                    log_event("Forcando interrupcao do App " &amp; NomeDoApp, app_name) of commonScript
                end try
            end if
        end repeat
    end tell

    tell application "System Events" to set myPID to (unix id of processes whose name is app_name)
    do shell script ("/usr/bin/renice 18 " &amp; myPID)

    delay 60

end repeat


How can i make it a service, so it only run 1 instance and when the system starts, not at user logon?

Any other suggestions about my code?



EDIT

Here is my current (working) .plist located in /Library/LaunchAgents

&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;Disabled&lt;/key&gt;
    &lt;false/&gt;
    &lt;key&gt;EnableGlobbing&lt;/key&gt;
    &lt;false/&gt;
    &lt;key&gt;KeepAlive&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;ram.ramon.FecharProgramas&lt;/string&gt;
    &lt;key&gt;LowPriorityIO&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;Program&lt;/key&gt;
    &lt;string&gt;Applications/FecharProgramas.app/Contents/MacOS/FecharProgramas&lt;/string&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;


When i move it to /Library/LaunchDaemons the app doesn't work anymore.  

05/10/13 10:43:24,375 FecharProgramas[90]: 3891612: (connect_and_check) Untrusted apps are not allowed to connect to or launch Window Server before login.
05/10/13 10:43:24,376 FecharProgramas[90]: kCGErrorFailure: This user is not allowed access to the window system right now.
05/10/13 10:43:24,376 FecharProgramas[90]: _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
05/10/13 10:43:24,382 FecharProgramas[90]: kCGErrorInvalidConnection: CGSGetEventPort: Invalid connection


Do i need to trust my app? If so, how?
You can use launchd.plist or use a program like Lingon (which is easier to use to create a launchd plist).