Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 51 lines (45 sloc) 2.034 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
node.default['function_keys']['use_function_keys_as_function_keys'] = true

as_fn_keys = node.default['function_keys']['use_function_keys_as_function_keys'] ? "0" : "1"

# The following won't take effect until the person logs out & logs back in again.
# THE BELT
pivotal_workstation_defaults "Turn #{as_fn_keys ? "on" : "off" } function-keys-work-as-function keys" do
  domain '.GlobalPreferences'
  key 'com.apple.keyboard.fnState'
  boolean node.default['function_keys']['use_function_keys_as_function_keys']
end

# Attempt an interactive change. Two req'ts: 1) user must be logged in 2) assistive devices enabled
# THE SUSPENDERS
ruby_block "Fix Function Keys" do
  block do
    def are_we_logged_in?
      system("ps aux | grep SystemUI | grep -v grep")
    end

    def are_assistive_devices_enabled?
      system("osascript -e '
tell application \"System Events\"
set UI_enabled to UI elements enabled
end tell
if UI_enabled is false then
error \"access for assistive devices is NOT enabled! (This is not an error, just a warning)\"
else
return \"access for assistive devices IS enabled!\"
end if'")
    end

    # check if we are logged into the console
    if are_we_logged_in? && are_assistive_devices_enabled?
      system("osascript -e '
tell application \"System Preferences\"
set current pane to pane \"com.apple.preference.keyboard\"
end tell
tell application \"System Events\"
tell application process \"System Preferences\"
click radio button \"Keyboard\" of tab group 1 of window \"Keyboard\"
if value of checkbox \"Use all F1, F2, etc. keys as standard function keys\" of tab group 1 of window \"Keyboard\" is #{as_fn_keys} then
click checkbox \"Use all F1, F2, etc. keys as standard function keys\" of tab group 1 of window \"Keyboard\"
end if
end tell
quit application \"System Preferences\"
end tell'")
    end
  end
end
Something went wrong with that request. Please try again.