Code: Select all
Sub SaveClose
dim CpathNm as string, CpNQoo as string, sPath1 as string
rem ********************************************************************
rem First, get the path to the Document you are currently in.
rem ********************************************************************
GlobalScope.BasicLibraries.loadLibrary("Tools")
CpathNm=DirectoryNameoutofPath(ThisComponent.getURL(),"/")
L = LEN(CpathNm)
' MsgBox "CpathNm/L= " & CpathNm & "/ " & L
rem ********************************************************************
rem Next, The path returned starts with "file:///Users/MyDir/... then on to
rem whichever directories your application/Document was started from and was to be saved in.
rem I keep the Qoo.app and QLo.app AppleScipts in an personal, Application Folder,
rem but to launch them, I must know where the "/" is after "MyDir" to get the launch Path right.
rem The following code handles the variable length of "MyDir" associated with different computers.
rem ********************************************************************
If L < 15 then goto SnC2:
for N = 15 to L
If MID(CpathNm,N,1) = "/" then
M = N
CpNQoo = LEFT(CpathNm,M) & "Applications/Qoo.app"
'msgbox "CpNQoo = " & CpNQoo
goto SnC1:
Else
End If
next N
msgbox "Something is wrong, CpNQoo = " & CpNQoo
goto SnC2:
rem ----------------------------------------------------------------------
SnC1:
sPath1= CpNQoo
oSvc = createUnoService("com.sun.star.system.SystemShellExecute")
oSvc.execute(sPath1, "" , 0)
rem ----------------------------------------------------------------------
rem In LibraOffice The apple script QLo is triggered with
rem the following code:(without the rem's)
rem Keep in mind, the line above must be changed to QLo.app/Contents/MacOS/applet
rem instead of just Qoo.app. I.E.:
rem CpNQoo = LEFT(CpathNm,M) & "Applications/QLo.app/Contents/MacOS/applet"
rem ----------------------------------------------------------------------
rem sPath1= CpNQoo
rem shell(sPath1)
rem ----------------------------------------------------------------------
rem The AppleScript waits 3 seconds before quitting OpenOffice,
rem which gives enough time for your document to be
rem stored and disposed of before OO is terminated.
rem ----------------------------------------------------------------------
rem on run
rem delay 3
rem tell application "OpenOffice"
rem quit
rem end tell
rem end run
rem ----------------------------------------------------------------------
dim oDoc as Object
dim oDocCtrl as Object
oDoc = ThisComponent
oDocCtrl = oDoc.getCurrentController()
oDoc.store() ' Save...
DisposeDocument(oDoc) ' ... and close
SnC2:
End Sub
P.S. The code is really short without the REM Statements:
Code: Select all
Sub SaveClose
dim CpathNm as string, CpNQoo as string, sPath1 as string
GlobalScope.BasicLibraries.loadLibrary("Tools")
CpathNm=DirectoryNameoutofPath(ThisComponent.getURL(),"/")
L = LEN(CpathNm)
' MsgBox "CpathNm/L= " & CpathNm & "/ " & L
If L < 15 then goto SnC2:
for N = 15 to L
If MID(CpathNm,N,1) = "/" then
M = N
CpNQoo = LEFT(CpathNm,M) & "Applications/Qoo.app"
'msgbox "CpNQoo = " & CpNQoo
goto SnC1:
Else
End If
next N
msgbox "Something is wrong, CpNQoo = " & CpNQoo
goto SnC2:
SnC1:
sPath1= CpNQoo
oSvc = createUnoService("com.sun.star.system.SystemShellExecute")
oSvc.execute(sPath1, "" , 0)
rem ----- For Libra Office, replace the CpNQoo = Line with .... QLo.app and
rem add /Contents/MacOS.applet to the end of the line. I.E. ------
rem CpNQoo = LEFT(CpathNm,M) & "Applications/QLo.app/Contents.MacOS.applet"
rem sPath1= CpNQoo
rem shell(sPath1)
rem ----------------------------------------------------------------------
dim oDoc as Object
dim oDocCtrl as Object
oDoc = ThisComponent
oDocCtrl = oDoc.getCurrentController()
oDoc.store() ' Save...
DisposeDocument(oDoc) ' ... and close
SnC2:
End Sub