0

I need to be able to force a "Detect Display" via Keymando. I didn't see any examples on how to execute system commands. Any thoughts on how to do this?

Adam
  • 1,561
  • 2
  • 15
  • 25

2 Answers2

2

You can do this the same way you do in ruby, with backticks or system().

For example:

map "<Ctrl-u>" do 
  `osascript -e 'set volume output volume (output volume of (get volume settings) + 7)'`
end
Kevin Colyar
  • 818
  • 1
  • 8
  • 18
0

Thanks to Kevin and this article I got this working using this script. Hope this helps someone in the future.

# Detect Displays
map "<Cmd-Ctrl-d>" do
  `osascript -e '
    tell application "System Preferences" to activate
    tell application "System Events"
      tell process "System Preferences"
        click menu item "Displays" of menu "View" of menu bar 1
        tell button "Detect Displays" of window 1 to click
      end tell
    end tell
    tell application "System Preferences" to quit
  '`
end
Adam
  • 1,561
  • 2
  • 15
  • 25