Volume and Application Management

Greetings Xojo folks -

Xojo 2019 R3.1

In my program, I have an application that has been opened with FolderItem.Open. Can that app be closed, programatically? If so, how?

Also, in the same program, i have an SD card that has been put into a card reader by the user following prompts from the program. After the program is finished using the SD card, I would like to eject it so that the user does not have to do any more than pull out the card. I have had users who consistently forget to do the eject and damage the card. Is there a way to do this? Cross-platform!

Many thanks
Jim Wagner
Oregon Research Electronics

Short follow-up: I tried setting the secondary app’s folder item to nil, and that did nothing.


Technically yes… But certainly on the Mac, security may present an issue. NSRunningApplication API should allow you to find the application on the Mac and to issue the terminate command. However I have never tried this an App Store app (as I suspect it won’t work). It could also be done via AppleScript, but again you probably won’t be able to use it in the App Store and you should pre-register the applications that your app is to script.

For the Mac I can help here.

shell.execute "hdiutil eject " + diskUnixName

This code takes the diskPath and finds the unix name.

s.backend = "/bin/bash"
s.execute "df"

Dim disklist(-1) as string = split( s.result, endofLine.unIX )
Dim n,l as integer
Dim diskUnixName as string
n = ubound( diskList )

for l=0 to n
  if right( diskList( l ), len( diskPath( 0 ).left ) ) = diskPath( 0 ).left then
    diskUnixName = trim( nthField( diskList( l ), "  ", 1 ) )
  end if

Thank you very much, Sam.

This will never appear in the AppStore. It is a captive GUI for specialized products that I am building. This particular one rides along with sensitive equipment (think semiconductor fab equipment, for example) and records the shocks and jolts that it experiences while being moved from one place to another. Users need an app to configure it, recover the data at the end, and create a report about what did or did not happen.

Really appreciate your help. I can cope with AppleScript, I think. Windows and linux are a different piece of the puzzle. I would assume that the unmount will probably work with some variation on linux. That leaves Windows to probe.

For closing the app, I can always prompt the user to take some OS-specific action since the host OS is known with #if TargetXYZ. Would be nice to avoid that, but that is small-stuff compared to ejecting the SD card.


James Wagner
Oregon Research Electronics

You are welcome.

That makes life a heck of a lot easier!

I can whip you up a short demo that would use NSRunningApplication, find the application via bundle identifier and issue the terminate command. This will save you the nightmare of AppleScript’s recent security crap.

Do you have a copy of the Ohanaware App Kit?

I am afraid that I can not help there at the moment.

Thanks for the offer. For now, I am going to go with an OS-dependent prompt to close the other app, manually,

Your MacOS eject example is a great piece to get me started.

Best wishes

1 Like

I’m using this shell command to kill a running helper:

'kill app if running
dim theCommand as String
theCommand = "ps -axwwopid,command | grep '" + PropertyValue("App.MacOSXAppName") +" $' | grep -v grep | awk '{print $1}'"
dim theResult as String
theResult = DoShellCommand(theCommand)
if theResult <> "" then
  theCommand = "kill " + theResult
  theResult = DoShellCommand(theCommand)
end if
1 Like

Thank you Beatrix!

That looks very useful.


As for quitting, have you considered just using a temporary file or a socket maybe?

For instance, you could have the app look for a specifically named file in the temporary folder and if it appears, quit the app.

Same concept for an IPCSocket. The parent app could just make a connection and send a command telling it to quit.