[Solved] Open remote folder

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
bartjeman
Posts: 177
Joined: Sun Jan 03, 2010 6:23 am
Location: Toronto

[Solved] Open remote folder

Post by bartjeman »

I have a macro that saves the sheet to our server
I store the URL in variable "Url", and write to the server with: oDoc.StoreAsUrl(Url,Array())
This all works fine

Since we often have to send these files by email after they are created, it would be convenient to open the folder right away so we can drag the file to the email app.

I'd appreciate some snippets to get me going

Thanks!
Last edited by bartjeman on Fri Aug 17, 2018 11:37 pm, edited 1 time in total.
OpenOffice 4.1.7 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open remote folder

Post by Villeroy »

A function which returns an com.sun.star.beans.URL struct from a given URL

Code: Select all

Function getURLStruct(sURL$, Optional service$)
Dim srv, url , bOK as Boolean
   srv = createUnoService("com.sun.star.util.URLTransformer")
   url = createUnoStruct("com.sun.star.util.URL")
   url.Complete = sURL
   if isMissing(service) then
      bOK = srv.parseStrict(url)
   else
      bOK = srv.parseSmart(url, service)
   endif
   if bOK then getURLStruct = url
End Function
Now you get the folder path and a file picker in this path like this:

Code: Select all

oURL = getURLStruct(strURL)
sPath = oURL.Protocol & oURL.Path
sFile = pickFile("Some Title", sPath, "Spreadsheet (*.ods)", "*.ods")
And this is my simplified file picker:

Code: Select all

Function pickFile(sTitle$, sInit$, sFilterLabel$, sPattern$, Optional bMulti as Boolean) AS String
REM dialog starts at office default directory if sInit = ""
if isMissing(bMulti) then bMulti = False
Dim oPicker, x()
	oPicker = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
	oPicker.setTitle(sTitle)
	oPicker.setDisplayDirectory(sInit)
	oPicker.setMultiSelectionMode(bMulti)
	oPicker.appendFilter(sFilterLabel, sPattern)
	if oPicker.execute() then
		x = oPicker.getFiles()
		if bMulti then
			pickFile = x()
		else
			pickFile = x(0)
		endif
	endif
End Function
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
bartjeman
Posts: 177
Joined: Sun Jan 03, 2010 6:23 am
Location: Toronto

Re: Open remote folder

Post by bartjeman »

Thanks very much Villeroy
Not sure if I need a file picker, I just want to open the containing folder based on a given path

I have already established the path and created the URL like this:
Url = ConvertToUrl(Path)

How do I open the folder?

Thanks!
OpenOffice 4.1.7 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open remote folder

Post by Villeroy »

StarBasic talks to the office suite.
For an Explorerr window you have to negotiate with Windows.
StarBasic's "Declare" statement may build a bridge to your operating system.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
bartjeman
Posts: 177
Joined: Sun Jan 03, 2010 6:23 am
Location: Toronto

Re: Open remote folder

Post by bartjeman »

Thanks Villeroy
Looks like Declare is used to access Windows DLL. I did some searching but the only example is how to make the PC make beep sound :-)
Can I run some VB in my script, like this?
SetCurrentDirectory("Folder_Path")
Process.Start("explorer.exe")

I just found this example which opens a file, maybe there is a way to use this to open a folder
Dim FDir As String, PdfFile As String
Dim objService As Object
...
objService = createUnoService("com.sun.star.system.SystemShellExecute")
objService.execute(FDir & "\" PdfFile, "", 0)
OpenOffice 4.1.7 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open remote folder

Post by Villeroy »

Sorry, I forgot the shell command. Lookup "shell" in the StarBasic help.

LInux examples:
shell "/usr/bin/nautilus",3,"file:///home/andreas/Dokumente/LibreOffice"
shell "/usr/bin/nautilus",3,"/home/andreas/Dokumente/LibreOffice"

"/usr/bin/nautilus" is my file manager, 3 brings the normally sized window to front.
My file manager accepts file:/// URLs
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
bartjeman
Posts: 177
Joined: Sun Jan 03, 2010 6:23 am
Location: Toronto

[Solved] Open remote folder

Post by bartjeman »

OK I got it
this works

Code: Select all

Sub OpenFolder
Dim Path as String, Folder as String, Url as string
Dim oDoc as Object
oDoc = ThisComponent
Url = oDoc.URL
Path = ConvertFromUrl(Url)
Folder = DirectoryNameoutofPath(Url(),"/")
Folder = ConvertFromUrl(Folder)
Shell("C:\Windows\explorer.exe", 1, Folder)
End Sub
OpenOffice 4.1.7 on Windows 10
Post Reply