Ho il seguente applescript
in bundle come .app
(utilizzando Platypus) e l'avvio sull'accesso utente (12,4 MB per ciascun utente)
#!/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) & "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 " & NomeDoApp & " encerrado com sucesso", app_name) of commonScript
on error
do shell script "killall " & quoted form of NomeDoApp
log_event("Forcando interrupcao do App " & 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 " & myPID)
delay 60
end repeat
Come posso renderlo un servizio, quindi esegue solo 1 istanza e all'avvio del sistema, non all'accesso dell'utente?
Qualche altro suggerimento sul mio codice?
Modifica
Ecco il mio attuale (funzionante) .plist
situato in /Library/LaunchAgents
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>EnableGlobbing</key>
<false/>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>ram.ramon.FecharProgramas</string>
<key>LowPriorityIO</key>
<true/>
<key>Program</key>
<string>Applications/FecharProgramas.app/Contents/MacOS/FecharProgramas</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Quando lo sposto in /Library/LaunchDaemons
l'app non funziona più.
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
Devo fidarmi della mia app? Se sì, come?