open a folder when you know the full path

I’m building an app to open a lot of folders. Each button opens a different folder. (see attached screenshot) This is for work. I open the same folders all day long. I had been doing this in Applescript but know the time has come to do it in XOJO. Here is the Applescript code for what it is worth.

tell application “Finder”
open folder “Macintosh HD:Users:shawn:Desktop:ATP:”
end tell

how would do this in XOJO. I have looked the GetFolderItem ( page and can’t figure it out.

functions, methods, and classes…my head is spinning

“…it is safer to use the Volume function and the Child method of the FolderItem class.”

Dim sh As New Shell() sh.Execute("open /Users/shawn/Desktop/ATP")

Eli, GENIUS. Thank you sooooo much. Now, can I place and position the window. (20,30,500,300)?

what is a shell, can I read up on that somewhere

I found this:
link text

but how do I get the ID of the frontmost or active Mac Finder Window

found this, its UNIX, how do you implement into XOJO, its greek to me

link text

Why don’t you use your AppleScripts in Xojo? You can either use the name of the folder as parameter in hardcoded AppleScripts or you can do AppleScripts fully dynamic with the MBS plugin (see for a wrapper) or the shell. The only problem with using the shell is quoting. It’s really awful but it works fine.


here is what I currently use and it works VERY well, no issues. I just drag the script from desktop to scripts folder in XOJO. I

dim mshell as new shell mshell.Execute searchqnap

I downloaded your link, can’t figure it out, here is a screenshot.

I found these but no one can help me use them

xdotool getwindowpid
xdotool windowmove
xdotool windowsize

link text

IMHO, the simplest cross-platform way in Xojo to open folders is to get a FolderItem to the path then use Launch

Dim f as FolderItem
Dim dir as FolderItem
dir = SpecialFolder.Desktop
dirCount = dir.Count
For i as Integer = 1 To dirCount
  f = dir.Item(i)
  If f <> Nil And f.Exists and f.Directory Then
  End If

The above should open every folder on the desktop. How Launch behaves depends on what type of FolderItem you pass it. In the case of a folder, it “opens” it in that OS’s normal manner. If an application, it starts the application. If another type of file (say a PDF) it starts whatever application is defined as the default program to handle that type of file, and passes it the FolderItem so it opens it.

Also notice that FolderItem.Count is a one-based array, whereas most arrays in Xojo are zero-based.

Using Launch as well :

GetFolderItem("/Users/shawn/Desktop/ATP", FolderItem.PathTypeShell).Launch

Michel Bujardet thank you very much. Do you know how to place the newly opened window at x20, y20 and also size the window like 500 wide 400 high, using XOJO.

You could possibly do that with AppleScript, but since it requires a call to System Events, that will never be accepted for the MAS.

Long ago, I had done something of that nature with declare to manage where the printer dialog was placed on Windows, using GetFrontWindows and SetWindowPos. I mention it since you posted in General, not in macOS.

Why would you want to do this? I don’t think Xojo is the right tool for the job.

It may be stating the obvious, but for Xojo application windows you set the size and placement via properties of that window, such as Width, Height, Top, Left. The problem here is you are wanting to adjust a window that is NOT part of the Xojo application. In order to do that, you need to perform platform specific calls to the OS to modify another application’s window. Under most circumstances, it is not considered prudent to modify windows outside your own application. I get where you are coming from in this scenario though, since your app is the one opening these windows.

The general way to control other app’s windows is via the Declare statement. A caveat here is that it not only depends on which platform you are running, but also will depend on 32-bit or 64-bit versions. You don’t mention here what you need to target, and you put this thread in the General forum section. So I presume you are looking for cross-platforms ways of doing this.

Over the years, some users have created things to help use declares for a given environment. Probably the most widely used of these can be found with forums searches for “MacOSLib” or “Windows Functionality Suite”

But these originated before you had to also worry about 64-bit builds, so they are outdated. For more info, see threads like this and this . But these should also show up in any forum searches you do for the names I gave above.

Note that in your case you don’t need everything these extensions have to offer, so you can cherry pick out just the parts you need and create 64-bit versions of only those declares.

Indeed, it is always a bit frustrating to have someone post in General without much explanation about the platform requirements. It is far easier when someone posts in macOS, Windows or Linux.

I would not even bother trying to control a terminal window on Mac. There are simply no declares to do so AFAIK, only AppleScript, and it is taboo if the app is to go in the MAS.

On Windows the declares are fairly simple and work flawlessly, but yet again, it seems not quite right to try and control the command prompt.

From what I understand the OP wants to do, he may look into the project Example Projects/Advanced/Shell/Interactive Shell.xojo_binary_project which enables to open your own “terminal” window in Xojo.

I believe he is trying to size/place multiple Finder windows, not terminal windows. You may be thinking terminal because one reply noted the Finder window can be obtained using a shell to issue the “open” command. But IMHO it makes much more sense to simply use [FolderItem].Launch and forgo the shell.