Skip to content

Instantly share code, notes, and snippets.

@Daij-Djan
Created January 19, 2017 15:24
Show Gist options
  • Save Daij-Djan/730cc9ef36e165875ae8c81e4835da8c to your computer and use it in GitHub Desktop.
Save Daij-Djan/730cc9ef36e165875ae8c81e4835da8c to your computer and use it in GitHub Desktop.
Run a local Webserver with Sinatra that can do actions on your Mac. I mainly want /quiet for my hacked amazon dash button And/Or home control
#!/usr/bin/env ruby
require 'sinatra'
get '/hello' do
value = `osascript -e 'tell app "System Events" to display dialog "Hello"'`
end
get '/lock' do
value = `"/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession" -suspend`
end
get '/quiet' do
value = `osascript -e 'tell application "iTunes" to pause'`
value = `osascript -e 'tell application "System Events" to tell process "iTunes" to set visible to false'`
value = `osascript -e 'tell application "Spotify" to pause'`
value = `osascript -e 'tell application "System Events" to tell process "Spotify" to set visible to false'`
end
@Daij-Djan
Copy link
Author

run it in the terminal: terminal isn't sandboxed ;) it (obviously) doesn't work if run in a sandbox

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