Last active
September 12, 2025 14:45
-
-
Save encoreshao/840d320cc2dd00cb2245df5ffcc11217 to your computer and use it in GitHub Desktop.
Add Custom Loaded Agents on MacOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/expect -f | |
| # SHELL path /Users/encore/.scripts/startup/add_ssh_key.sh | |
| # Path to your SSH key | |
| set ssh_key "$env(HOME)/.ssh/id_ed25519" | |
| # Check if the key exists | |
| if {![file exists $ssh_key]} { | |
| puts "SSH key not found at $ssh_key" | |
| exit 1 | |
| } | |
| # Add the key to ssh-agent | |
| spawn ssh-add $ssh_key | |
| expect "Enter passphrase for $ssh_key:" | |
| send "mypassword\r" | |
| expect eof |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- ~/Library/LaunchAgents/com.user.ssh-add.plist --> | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>Label</key> | |
| <string>com.user.ssh-add</string> | |
| <key>ProgramArguments</key> | |
| <array> | |
| <string>/Users/encore/.scripts/startup/add_ssh_key.sh</string> | |
| </array> | |
| <key>RunAtLoad</key> | |
| <true/> | |
| <key>StandardErrorPath</key> | |
| <string>/tmp/ssh-add.err</string> | |
| <key>StandardOutPath</key> | |
| <string>/tmp/ssh-add.out</string> | |
| </dict> | |
| </plist> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Launchd it
It will run every time you log in.
List Loaded Agents