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
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 ) )
exit
end if
next
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.
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.