1 (*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: main.applescript,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 *************************************************************************)
31 (*==== (global variables as get-functions) ====*)
34 return (((
path to me)
as string) &
"Contents:")
37 on getOOResourcesPath()
38 return (((
path to me)
as string) &
"Contents:Resources:")
39 end getOOResourcesPath
42 return (
getOOInstallPath() &
"MacOS:")
46 -- set this to absolute path when debugging
47 return (((
path to me)
as string) &
"Contents:Resources:Scripts:")
50 on getOOUserSettingsPath()
51 return (((
path to home
folder)
as string) &
"Library:Application Support:OpenOffice.org:%USERDIRPRODUCTVERSION:")
52 end getOOUserSettingsPath
54 on getOOUserFontPath()
55 return (
getOOUserSettingsPath() &
"user:fonts:")
59 return (((
path to home
folder)
as string) &
"Library:Logs:")
63 return (
" &>/dev/null & echo $!")
as string
67 -- the default handlers: run, open, idle, quit
72 logEvent(
"(Scripts/main) Running OpenOffice.org")
84 -- close icon only if ooo has terminated
85 if (
hasOOoQuit())
then
88 -- check all x seconds if ok to quit
93 if (
hasOOoQuit())
then
98 -------------------------------------------------------------
103 -- Check for the required version of Mac OS X
104 if (
not atLeastOSXVersion(
10,
3,
0))
then
105 display dialog getMessage(
"ERROR_NEED_PANTHER")
109 -- Check for that OOo can be found
110 if (
not isRealPath(
getOOProgramPath()))
then
111 display dialog getMessage(
"ERROR_OOO_NOT_FOUND")
115 if (
not isRealPath(
getOOUserFontPath()))
then
116 set createUserFont
to "mkdir -p " & (quoted form
of POSIX
path of getOOUserFontPath()) &
"; "
117 do shell
script createUserFont
120 -- If no crash occured before, ~/Library/Logs does not exist, and OpenOffice.org cannot be started
121 if (
not isRealPath(
getUserLogsPath()))
then
122 set createUserLogsPath
to "mkdir -p " & (quoted form
of POSIX
path of getUserLogsPath()) &
"; "
123 do shell
script createUserLogsPath
126 -- Checks are ok, now do the PostInstall stuff (e.g. fondu)
128 -- load helper library
129 set postinstall
to load script alias Â
130 (
getScriptPath() &
"PostInstall.scpt")
131 -- execute the postinstall script
140 if (
isRealPath(
getOOProgramPath()))
then
141 -- set the location of soffice binary
142 set soffice
to (quoted form
of (POSIX
path of getOOProgramPath() &
"soffice"))
144 set isRunning
to do shell
script "_FOUND_=`ps -wx -o command | grep " & soffice &
" | grep -v grep`; echo $_FOUND_"
145 if isRunning
"" then
156 on openSoffice(aFile)
157 set theDisplay
to startXServer()
158 if (theDisplay
is equal to "error")
then
161 set theEnv
to "DISPLAY=" & theDisplay &
" ; export DISPLAY; "
162 set theCmd
to "sh " & (quoted form
of (POSIX
path of getOOProgramPath() &
"soffice")) &
" "
163 do shell
script theEnv & theCmd & aFile &
shellTerminator()
164 -- logEvent("open CMD: " & theEnv & theCmd & aFile)
168 -- helper function to start X11 server
172 set XSettingsList
to findXServer()
173 set whichserver
to item 1 of XSettingsList
174 set Xserverloc
to item 2 of XSettingsList
177 -- logEvent("(scripts/main) X settings: " & whichserver & "--" & POSIX path of Xserverloc)
178 -- set whichserver to "NOXSERVER"
180 -- if nothing really was found, display an error message.
181 if (whichserver
is equal to "NOXSERVER")
then
183 display dialog getMessage(
"ERROR_NEED_X11")
buttons {
"Quit",
"More Info"}
default button "More Info"
184 if the button returned
of the result
is "Quit" then
187 -- if more info is chosen, then open a help web page
188 do shell
script "open http://porting.openoffice.org/mac/faq/installing/X11.html"
189 -- cannot continue, so quit the script
195 set now_running
to ""
196 set now_running
to do shell
script "INX=`ps -wcx | grep " & quoted form
of (whichserver &
"$") &
"`; echo $INX"
197 if whichserver =
"NOXSERVER" then
198 -- display dialog "No XServer Found"
199 set now_running
to "Skip"
201 if now_running =
"" then
202 if whichserver =
"X11" then
203 set x11cmd
to quoted form
of (Xserverloc &
"/Contents/MacOS/X11") &
shellTerminator()
204 do shell
script x11cmd
206 set x11pid
to the result
207 -- wait until the window manager is started which is the second child process of x11
208 set numchildrencmd
to "ps -x -o ppid | grep " & x11pid &
" | wc -l"
210 set d
to current date
212 repeat while numchildren
2
213 set d
to current date
215 -- give up after 30 seconds
217 display dialog "Command timed out"
220 set result
to do shell
script numchildrencmd
221 set numchildren
to result
as integer
223 else -- startup XDarwin
224 do shell
script "open " & quoted form
of Xserverloc &
shellTerminator()
225 do shell
script "sleep 4"
228 if whichserver
is equal to "X11" then
229 -- the DISPLAY variable is different for every user currently logged in
230 -- X11 passes the DISPLAY as the last command line parameter to its child process
231 -- we can use ps to read the command line and parse the trailing :0, :1, or whatever
232 set xdisplay
to do shell
script "ps -wx -o command | grep X11.app | grep \":.$\" | sed \"s/^.*:/:/g\""
233 --display dialog xdisplay
236 -- TODO: find out how XDarwin does it
242 on openFiles(fileList)
243 if (
count of fileList) >
0 then
244 repeat with i
from 1 to the count of fileList
245 set theDocument
to (
item i
of fileList)
246 set theFilePath
to (quoted form
of POSIX
path of theDocument)
247 set theFileInfo
to (info
for theDocument)
248 openSoffice(theFilePath)
249 logEvent(
"(Scripts/main) Open file: " & theFilePath)
255 (* ===== (Helper functions) ======= *)
257 -- get a localized string
260 if (aKey
is equal to "YES_KEY")
then
264 if (aKey
is equal to "NO_KEY")
then
268 if (aKey
is equal to "ERROR_OOO_NOT_FOUND")
then
269 return "OpenOffice.org was not found on your system. Please (re-)install OpenOffice.org first."
272 if (aKey
is equal to "ERROR_NEED_PANTHER")
then
273 return "This build of OpenOffice.org cannot be run on this system, OpenOffice.org requires MacOSX 10.3 (Panther) or newer system"
276 if (aKey
is equal to "ERROR_NEED_X11")
then
277 return "OpenOffice.org for Mac OS X cannot be started, because the X11 software is not installed. Please install Apple X11 first from the Mac OS X install DVD. More information: http://porting.openoffice.org/mac/faq/installing/X11.html"
283 -- function for logging script messages
284 on logEvent(themessage)
285 set theLine
to (do shell
script Â
286 "date +'%Y-%m-%d %H:%M:%S'" as string) Â
288 do shell
script "echo " & quoted form
of theLine & Â
289 " >> ~/Library/Logs/OpenOffice%USERDIRPRODUCTVERSION.log"
293 -- function for checking if a path exists
299 -- error number -43 from aPath
300 -- display dialog "NotRP -- " & aPath
305 -- try to find X11 server on the Mac OS X system
306 -- return value: the found server or "NOXSERVER"
308 -- First try standard X11 location, then try standard XDarwin location
310 set whichserver
to "NOXSERVER"
311 --Utilities folder of system
312 set Xserverloc
to ((
path to utilities
folder from system
domain)
as string) &
"X11.app:"
313 --display dialog " Xserverloc" & Xserverloc
314 if (
isRealPath(Xserverloc))
then
315 set whichserver
to "X11"
316 set Xserverloc
to (POSIX
path of Xserverloc)
318 --Applications folder of system
319 set Xserverloc
to ((
path to applications
folder from system
domain)
as string) &
"XDarwin.app:"
320 if (
isRealPath(Xserverloc))
then
321 set whichserver
to "XDarwin"
322 set Xserverloc
to (POSIX
path of Xserverloc)
326 -- if nothing found yet try using locate, first with X11.app and then with XDarwin.app
327 if (whichserver
is equal to "NOXSERVER")
then
328 set Xserverloc
to do shell
script "locate X11.app/Contents/MacOS/X11 | sed -e 's-/Contents/MacOS/X11--g'"
329 if Xserverloc
"" then
330 set whichserver
to "X11"
334 if (whichserver
is equal to "NOXSERVER")
then
335 set Xserverloc
to do shell
script "locate XDarwin.app/Contents/MacOS/XDarwin | sed -e 's-/Contents/MacOS/XDarwin--g'"
336 if Xserverloc
"" then
337 set whichserver
to "XDarwin"
341 return {whichserver, Xserverloc}
345 -- Test for a minimum version of Mac OS X
346 on atLeastOSXVersion(verMajor, verMinor, verStep)
347 -- The StandardAdditions's 'system attribute' used to be the Finder's 'computer' command.
348 tell application "Finder" to set sysv
to (system attribute
"sysv")
350 -- Generate sysv-compatible number from given version
351 set reqVer
to ((verMajor
div 10) *
4096 + (verMajor
mod 10) *
256 + verMinor *
16 + verStep)
354 -- display dialog ("RV:" & reqVer & " < " & sysv as string)
356 -- set major to ((sysv div 4096) * 10 + (sysv mod 4096 div 256))
357 -- set minor to (sysv mod 256 div 16)
358 -- set step to (sysv mod 16)
359 -- display dialog ("Your Mac OS X version: " & major & "." & minor & "." & step)
361 if (reqVer > sysv)
then
366 end atLeastOSXVersion