--- main.org.applescript 2006-07-18 15:55:17.000000000 +0300 +++ main.org.applescript 2006-07-18 15:57:17.000000000 +0300 @@ -71,6 +71,9 @@ on run if (preRun()) then openSoffice("-") + if (hasOOoDaemonQuit()) then + runOOoDaemon() + end if end if end run @@ -82,17 +85,20 @@ on idle -- close icon only if ooo has terminated - if (hasOOoQuit()) then - tell me to quit - end if + --if (hasOOoQuit()) then + -- tell me to quit + --end if -- check all x seconds if ok to quit - return 3 + --return 3 end idle on quit - if (hasOOoQuit()) then - continue quit - end if + -- kill all OOo instances, all windows and the daemon + set theCmd to "killall soffice.bin" + do shell script theCmd & " &>/dev/null & echo $!" + logEvent("(scripts/main) OpenOffice.org daemon stopped.") + + continue quit end quit ------------------------------------------------------------- @@ -133,13 +139,29 @@ return true end preRun +on hasOOoDaemonQuit() + if (isRealPath(getOOProgramPath())) then + -- set the location of soffice binary + set soffice to POSIX path of getOOProgramPath() & "soffice" + + set isRunning to do shell script "_FOUND_=`ps -wx -o command | grep \"" & soffice & "\" | grep quickstart | grep -v grep `; echo $_FOUND_" + if isRunning ­ "" then + return false + else + return true + end if + else + return true + end if +end hasOOoDaemonQuit + on hasOOoQuit() if (isRealPath(getOOProgramPath())) then -- set the location of soffice binary set soffice to POSIX path of getOOProgramPath() & "soffice" - set isRunning to do shell script "_FOUND_=`ps -wx -o command | grep \"" & soffice & "\" | grep -v grep`; echo $_FOUND_" + set isRunning to do shell script "_FOUND_=`ps -wx -o command | grep \"" & soffice & "\" | grep -v grep | grep -v quickstart`; echo $_FOUND_" if isRunning ­ "" then return false else @@ -150,6 +172,18 @@ end if end hasOOoQuit +-- Run OOo hidden in the background to mimic Mac OS X like behaviour +on runOOoDaemon() + set theDisplay to startXServer() + if (theDisplay is equal to "error") then + return + end if + set theEnv to "DISPLAY=" & theDisplay & " ; export DISPLAY; " + set theCmd to "sh \"" & POSIX path of getOOProgramPath() & "soffice" & "\" " + do shell script theEnv & theCmd & " -quickstart " & " &>/dev/null & echo $!" + logEvent("(scripts/main) OpenOffice.org daemon started.") +end runOOoDaemon + on openSoffice(aFile) set theDisplay to startXServer() @@ -271,7 +305,7 @@ -- function for logging script messages on logEvent(themessage) set theLine to (do shell script  - "date +'%Y-%m-%d %H:%M:%S'" as string)  + "date +\"%Y-%m-%d %H:%M:%S\"" as string)  & " " & themessage do shell script "echo '" & theLine & "'" &  " >> ~/Library/Logs/OpenOffice2.log"