Page 1 of 1

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

PostPosted: Fri Mar 26, 2021 3:00 pm
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   Expand viewCollapse view
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?

Re: Will this macro work on mac?

PostPosted: Fri Mar 26, 2021 3:16 pm
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.

Re: Will this macro work on mac?

PostPosted: Sat Mar 27, 2021 12:00 am
by robleyd
You seem to have a typo:
Code: Select all   Expand viewCollapse view
Dim oPahtOS as String
....
oPathOS = ConvertFromURL(Folder)

Re: Will this macro work on mac?

PostPosted: Sat Mar 27, 2021 8:05 am
by Zizi64
Code: Select all   Expand viewCollapse view
Dim oPahtOS as String
....
oPathOS = ConvertFromURL(Folder)


Use the

Code: Select all   Expand viewCollapse view
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).

Re: Will this macro work on mac?

PostPosted: Sat Mar 27, 2021 3:56 pm
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   Expand viewCollapse view
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.

Re: Will this macro work on mac?

PostPosted: Sat Mar 27, 2021 4:48 pm
by JuanPa
Thanks for all the answers. Finally this is the code I have used:

Code: Select all   Expand viewCollapse view
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!