How to eject an external drive in C# on MacOS

Mr.XMr.X CAMember ✭✭

Hopefully this is the right forum - I cannot find anything about this on the 'net. What function can I use to properly eject an external drive using C# on MacOS?

Best Answer

Answers

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    I'd start by searching for "macos unmount usb API", which will bring you towards "man diskutil" and some stack overflow posts.

  • Mr.XMr.X CAMember ✭✭

    Thank you for your reply.
    I have searched the 'NET pretty exhaustively already. The only command I've found is using terminal and the command line. "diskutil unmount {drive name}"
    Is there no .NET library function? Nothing in System.IO or anywhere? No Xamarin/Mono function?

  • Mr.XMr.X CAMember ✭✭
  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Unsure, maybe that NSWorkspace API does the same thing? Have you tried it?

  • Mr.XMr.X CAMember ✭✭

    I have not. I'm completely new to Mac programming. I was hoping to find some sources of info on C# .NET programming for Mac but there is so little out there.
    I appreciate you trying to help.

  • Mr.XMr.X CAMember ✭✭

    Any idea where I can find information on using that MonoMac library in a C# .NET program?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    As you are new to Xamarin.Mac, I would start with the documentation listed here:

    https://forums.xamarin.com/discussion/31680/welcome-to-the-xamarin-mac-forums-and-faq#latest

    In particular https://docs.microsoft.com/en-us/xamarin/mac/platform/target-framework explains a bit about the differences between BCLs and what libraries can be reused under what target frameworks.

  • Mr.XMr.X CAMember ✭✭

    Thank you, I've read through all of that now, and it doesn't seem to help...

    I think maybe I need to be "using" AppKit in my program to access these additional library commands? I can't seem to add the line "using AppKit" in my console app. It doesn't recognize the reference. The "target-framework" page you linked to doesn't show the same screen as my app. I looked to add the reference and AppKit is not listed. I looked to download an AppKit package, and it's not listed.
    ??

  • Mr.XMr.X CAMember ✭✭

    NSWorkspace.Unmountandeject() works properly, but only when used in a project that references Xamarin.Mac. and will allow me to reference "Appkit".
    I have no idea why I cannot reference Xamarin.Mac in my GTK or console solutions. Damn this is hard.

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    So the reason you can't just reference "Xamarin.Mac.dll" and go is that unlike p/invoking into C frameworks, calling into Cocoa / Objective-C is significantly less trivial. There is trampoline code that needs to be linked in, you have to register with the Objective-c runtime, etc, etc.

    We handle all of this for you when your "main" app is a Xamarin.Mac one, but that can be difficult to move to for existing apps without some work.

    Before anyone does too much digging, how much macOS integration are you expecting to need in your existing GTK application? One single API call you can hack around is significantly different than a bunch.

  • Mr.XMr.X CAMember ✭✭

    Difficult to answer, since I'm just starting out. Coming from 15+ years of using VS for Windows, where everything is just so damn easy.
    I need to be able to build GUI apps for Mac, and since GTK# seems to be the only GUI with a designer for VS2017 for Mac that's easy to use, that's where I'm starting. I wish there were Xamarin forms implemented for Mac, but I've given up waiting.
    So, I guess at this point, I'd like to be able to use AppKit calls within a GTK# application, or GTK# calls within a Xamarin.Mac application. Is that possible?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    As you noted, there is no built in VSfM editor for macOS storyboards, not any announced plans right now. That means Xamarin.Mac development involves using Interface Builder in Xcode, which isn't too terrible once you get used to it. I'd start by going through https://docs.microsoft.com/en-us/xamarin/mac/get-started/hello-mac which covers IB use.

    Another option is to use Xamarin.Forms which now supports macOS as a backend.

    I will note that GTK# apps don't "really" look like macOS applications due to not using the native controls/styling, but that's a tradeoff you can decide upon.

    You could likely create a Xamarin.Mac application and host a GTK# application within in, but I'd consider that more hassle than it's worth honestly, dealing with two even loops/etc is going to be a source of issues.

  • Mr.XMr.X CAMember ✭✭

    Thank you once again.

    Just trying to navigate all this is very confusing.

    You said:

    As you noted, there is no built in VSfM editor for macOS storyboards, not any announced plans right now. That means Xamarin.Mac development involves using Interface Builder in Xcode, which isn't too terrible once you get used to it. I'd start by going through https://docs.microsoft.com/en-us/xamarin/mac/get-started/hello-mac which covers IB use.

    Another option is to use Xamarin.Forms which now supports macOS as a backend.

    I would like to use Xamarin.Forms, but I see no GUI editor for them when creating MacOS apps. I find so much of IB really confusing. The drag/drop/move/resize for controls in Windows Forms is so incredibly easy. As is double-click-to-add-an-event-handler system.
    Are there any courses anywhere on how to create GUI apps for MacOS using VSfM? Xamarin University seems to be all about Mobile, not desktop MacOS apps...

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    There is no GUI editor for editing xaml in XM, but it's generally just as easy as using some GUI editors.

    The walkthrough (https://docs.microsoft.com/en-us/xamarin/mac/get-started/hello-mac) I previously linked goes through a simple GUI app with VSfM and Xamarin.Mac.

  • Mr.XMr.X CAMember ✭✭

    I've gone through the walkthrough and built that app. What I really need is a course on specifically creating C# GUI apps in VS2017 for Mac. Xamarin University only does Mobile stuff, and I've seen nothing else.
    Surprised there aren't more people looking for additional help on this subject - it's extremely difficult making that transition from Windows to Mac without all the great tools that VS for Windows has.

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    I don't believe there is any Xamarin.Mac specific training on the University so far. You could contact them with the idea, the e-mail appears to be [email protected]

    Beyond that, picking it up as you go with the walkthroughs / samples is likely your best bet.

Sign In or Register to comment.