Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env osascript
-- based on http://stackoverflow.com/a/23018886/344821
tell application "System Events" to tell process "SystemUIServer"
set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
click bt
tell (first menu item whose title is "CMU keyboard") of menu of bt
click
tell menu 1
if exists menu item "Connect"
click menu item "Connect"
return "Connecting..."
else
click bt -- close main dropdown to clean up after ourselves
return "No connect button; is it already connected?"
end if
end tell
end tell
end tell
#!/usr/bin/env osascript
-- based on http://stackoverflow.com/a/23018886/344821
tell application "System Events" to tell process "SystemUIServer"
set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
click bt
tell (first menu item whose title is "CMU mouse") of menu of bt
click
tell menu 1
if exists menu item "Connect"
click menu item "Connect"
return "Connecting..."
else
click bt -- close main dropdown to clean up after ourselves
return "No connect button; is it already connected?"
end if
end tell
end tell
end tell
#!/usr/bin/env osascript
-- based on http://stackoverflow.com/a/23018886/344821
tell application "System Events" to tell process "SystemUIServer"
set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
click bt
tell (first menu item whose title is "CMU keyboard") of menu of bt
click
tell menu 1
if exists menu item "Disconnect"
click menu item "Disconnect"
return "Disconnecting..."
else
click bt -- close main dropdown to clean up after ourselves
return "No disconnect button; is it connected?"
end if
end tell
end tell
end tell
#!/usr/bin/env osascript
-- based on http://stackoverflow.com/a/23018886/344821
tell application "System Events" to tell process "SystemUIServer"
set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
click bt
tell (first menu item whose title is "CMU mouse") of menu of bt
click
tell menu 1
if exists menu item "Disconnect"
click menu item "Disconnect"
return "Disconnecting..."
else
click bt -- close main dropdown to clean up after ourselves
return "No disconnect button; is it connected?"
end if
end tell
end tell
end tell
#!/bin/bash
# Disables bluetooth on the local machine, and enables it on the remote,
# so that the keyboard/mouse reconnect to that one.
remote=${1:-office}
# remote bluetooth on
ssh $remote '/usr/local/bin/blueutil power 1'
# local bluetooth on
blueutil power 0
#!/bin/bash
# Enables target display mode on the remote machine,
# and turns bluetooth off there / on here so that the keyboard/mouse reconnect
# to this one.
remote=${1:-office}
# remote enable TDM
ssh $remote "osascript -e 'tell application "'"'"System Events"'"'" to key code 144 using command down'"
# remote bluetooth off
ssh $remote '/usr/local/bin/blueutil power 0'
# local bluetooth on
blueutil power 1
#!/bin/bash
remote=${1:-office}
bin/disconnect-keyboard.sh
bin/disconnect-mouse.sh
sleep 1
ssh $remote 'bin/connect-keyboard.sh && bin/connect-mouse.sh'
#!/bin/bash
# Enables target display mode on the remote machine.
remote=${1:-office}
# remote enable TDM
ssh $remote "osascript -e 'tell application "'"'"System Events"'"'" to key code 144 using command down'"
#!/bin/bash
remote=${1:-office}
remote_tdm.sh $remote
ssh $remote 'bin/disconnect-keyboard.sh && bin/disconnect-mouse.sh'
sleep 1
bin/connect-keyboard.sh
bin/connect-mouse.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.