Skip to content

Instantly share code, notes, and snippets.

@nutrino
Created May 13, 2022 15:45
Show Gist options
  • Select an option

  • Save nutrino/579bf0fb992039d66102a5ef78282cc6 to your computer and use it in GitHub Desktop.

Select an option

Save nutrino/579bf0fb992039d66102a5ef78282cc6 to your computer and use it in GitHub Desktop.
macOS prevent from accidental unmounting
#!/bin/bash
# https://stackoverflow.com/a/23716566
screen -D -RR test1 -X quit || true
screen -dmS test1
screen -r test1 -p 0 -X stuff $"cd /Volumes/SDUltra ^M"
@nutrino
Copy link
Author

nutrino commented May 13, 2022

https://stackoverflow.com/a/23716566

Where the return character, ^M, you need to enter using vim as
CTRL-V ENTER ESCAPE

@nutrino
Copy link
Author

nutrino commented May 13, 2022

https://tech.bejond.org/2020/05/05/How-to-make-mac-run-shell-on-startup/

/Library/LaunchAgents/prevent_unmount_service.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:</string>
    </dict>
    <key>Label</key>
    <string>prevent_unmount_service</string>
    <key>ProgramArguments</key>
    <array>
    <string>/Users/hcshin/prevent_unmount.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
    <key>LaunchOnlyOnce</key>        
    <true/>
    <key>StandardErrorPath</key>
    <string>/tmp/startup.prevent_unmount_service.stderr</string>
    <key>UserName</key>
    <string>hcshin</string>
    <key>GroupName</key>
    <string>admin</string>
    <key>InitGroups</key>
    <true/>
  </dict>
</plist>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment