[Solved] Macro to open an operating system folder on Mac

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
JuanPa
Posts: 2
Joined: Fri Mar 26, 2021 2:48 pm

[Solved] Macro to open an operating system folder on Mac

Post by JuanPa »

Hi.
I'm doing this macro for Base, but it doesn't work and I can't find specific information for Mac.
The purpose is to open the stored folder (not a file).
Does "explorer" really work on Mac too?

Code: Select all

Sub ShowFolder (Evento)
Dim oForm As Object
Dim Folder As String
Dim oPathLink as String
Dim oPahtOS as String

   oForm = Evento.Source.Model.Parent
   Folder= oForm.GetByName("Location").Text
   GlobalScope.BasicLibraries.LoadLibrary("Tools")   
   oPathOS = ConvertFromURL(Folder)
   Shell "explorer " & oPathOS

End Sub
How could I make it work?
Last edited by Hagar Delest on Sat Mar 27, 2021 5:44 pm, edited 1 time in total.
Reason: tagged solved.
Open Office 4.1.9
macOS 11.2.3
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Will this macro work on mac?

Post by Villeroy »

Try finder instead of explorer.
Where does the event object come from?
What are you trying to do? I can open a folder with a simple click on a hyperlink. If the folder exisits, it is shown in the system's prefered file manager.
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
robleyd
Moderator
Posts: 5055
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Will this macro work on mac?

Post by robleyd »

You seem to have a typo:

Code: Select all

Dim oPahtOS as String
....
oPathOS = ConvertFromURL(Folder)
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.1.2; SlackBuild for 24.2.1 by Eric Hameleers
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Will this macro work on mac?

Post by Zizi64 »

Code: Select all

Dim oPahtOS as String
....
oPathOS = ConvertFromURL(Folder)
Use the

Code: Select all

Option Explicit
directive at start of the code in a Module. Then the interpreter will warn you if a variable is not Dimensioned, or when there is a typo in the name inside the sub (when the used name is not same as the dimensioned one).
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Will this macro work on mac?

Post by Villeroy »

The easy way to open files, mails and any other URLs with a push button: viewtopic.php?t=98542&p=473296#p473296
This ivolves a one-click macro install, a button with a little extra, a query and the form being assigned to a macro (not a control). No code editing required.

If you need to open some directory with a button:
Create a query like:

Code: Select all

SELECT *, '/path/' || "DirName" AS "Path" FROM "MyTable"
as the source of your form. The query returns the complete "MyTable" plus a "Path" field with the concatenated paths. "MyTable" is the name of your table and "DirName" is the name of the column with the directory names. /path/ is the hardcoded path leading to the specified directory in system notation (would be like D:\Path\ under Windows). Use this form with this source together with the FileButton_Approve macro assigned to the form's approve event. This macro includes a conversion from system notation to a file-URL which is assigned to the push button when the underlying record has changed.
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
JuanPa
Posts: 2
Joined: Fri Mar 26, 2021 2:48 pm

Re: Will this macro work on mac?

Post by JuanPa »

Thanks for all the answers. Finally this is the code I have used:

Code: Select all

Sub ShowFolder(Evento)
Dim oForm As Object
Dim Folder As String

   oForm = Evento.Source.Model.Parent
   Folder= oForm.GetByName("Location").Text
  
   Shell "open " & Folder

End Sub
I changed "explorer" to "open" and it works fine!

Thanks!
Open Office 4.1.9
macOS 11.2.3
Post Reply