Create the files here:
- ~/Library/LaunchAgents/on-volume-mounted.plist
- ~/Library/Scripts/on-volume-mounted.rb
- ~/Library/Scripts/on-volume-mounted.yml
Update paths in file 'on-volume-mounted.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>on-volume-mounted</string> | |
| <key>Program</key> | |
| <string>/Users/freayd/Library/Scripts/on-volume-mounted.rb</string> | |
| <key>KeepAlive</key> | |
| <false/> | |
| <key>StartOnMount</key> | |
| <true/> | |
| </dict> | |
| </plist> |
| #!/usr/bin/env ruby | |
| require 'yaml' | |
| require 'open3' | |
| mounted_volume = nil | |
| Open3.popen3('mount') do |stdin, stdout, stderr| | |
| mounted_volume = stdout.readlines.last.match(/^\/dev\/\w+ on \/Volumes\/(.+?) \(.+?\)$/)[1] | |
| end | |
| exit if mounted_volume.nil? or ! File.exist?("/Volumes/#{mounted_volume}") | |
| home_folder = File.expand_path('~') | |
| settings = YAML.load_file(File.join(home_folder, 'Library', 'Scripts', 'on-volume-mounted.yml')) | |
| if settings.has_key?(mounted_volume) | |
| settings[mounted_volume].each do |command| | |
| system command | |
| end | |
| end |
| 'Cloud HD': | |
| - 'open /Applications/Dropbox.app' | |
| - 'open /Applications/Google\ Drive.app' | |
| 'Music HD': | |
| - 'open /Applications/iTunes.app' |