Connect/Mount eGPU using command line
A friend and I are looking into different ways to automate the process of auto-ejecting both the eGPU, to make it quicker and easier to disconnect and go when needed. (For anyone who didn't know, you can disconnect the eGPU via the command line with "/usr/bin/SafeEjectGPU Eject")
However, we're also looking for ways to automate the process of reconnecting the eGPU*. Does anyone know if a command for that exists? I can't see anything else in /usr/bin that refers to eGPU at all, not sure where else to look.
* in case you're wondering why on earth this would be helpful, the basic idea is to have the system automatically eject the eGPU just before system sleep, (so you can just unplug and go, say, first thing in the morning, without waking the system to do it) and have it automatically re-connect if the system wakes from sleep and detects that the eGPU wasn't actually unplugged.
(edit: word to better clarify)
@kstl See the documentation:
Per that, once the eject sequence finalizes, the eGPU must be physically re-connected for use. You could attempt partial ejection:
And test, though I doubt you'd be able to finalize the eject (and avoid the disconnect notification), since after wake, if the eGPU is not present, there is nothing to finalize. You can cancel the ejection process with:
Finally, another way of doing it is if one could figure out "disabling/enabling the thunderbolt port" temporarily (to simulate physical eject/plug).
Edit: Ok figured it out - not pretty, but does the job.
You will need a script with privileged access, or just use a privileged daemon.
This should do the trick. It shouldn't affect other non-PCI devices connected via Thunderbolt, but I have not tested specific cases.
That's super neat, thanks a lot!
I won't have a lot of time to spend on it this week due to school, but I'm going to try and integrate this into my Hammerspoon config. I can't see any reason why it wouldn't work. I'll report back if/when I have any success.
does the proposed solution work? I have the same requirement to have a script that automates the egpu behaviour. Would be really interested in a solution.
Thnaks in advance
Yes I've used the above commands to good effect in 10.14 Mojave. The eGPU connection after the kextload command can take a few seconds but it definitely works.
How do you trigger those command lines for sleep and wake up? Do you use a special program? I couldn't find anything suitable so far that is not 5 years old ;).
I haven't had sleep/wake issues where I needed the commands triggered by those so I just setup an automator quick action with the following applescript code.
It's probably not great code, but it works. Maybe switch the if/else statements for safety.
Ok, I will check if it is working for me as well or if I need to extend something. I will keep you updated if someone needs more input as well.
Thanks to you so far for your help.
I see I missed a few comments on this thread haha. Looks like the kext loading/unloading does the trick.
@patrick_b Check this out for some ways to trigger scripts on sleep/wake. I suppose the most "native, no-dependency" way of doing it is the LaunchDaemon example there (cannot confirm if it works myself).