I’ve been using my MacBook Pro under OS X 10.8 for a while now. There are still things that I find perplexing. For example, why is there no function lock key? Sure, I like to be able to adjust my screen brightness, but I also want to set bookmarks in Sublime Text and select all my units in StarCraft.
For those in the same boat, here is how I got a keyboard shortcut for toggling Function Lock.
My first attempt was to take an Applescript and and alias it as a command line tool. I found a script and set it up, but I was unsatisfied. I really wanted to be able to toggle functionality from the keyboard. This lead me to the following: setting up a service, and then creating a keyboard shortcut.
Set up a service
All flavors of Mac come with Automator. Because I use Alfred, it is simple to bring up. When Automator starts, choose to create a Service. In the search bar, search for “applescript” and choose “Run Applescript”. Paste the following and save the service with a useful name like “Function Toggle” (script source: rezecib on http://forums.macrumors.com/showthread.php?t=383969)
tell application "System Preferences" set current pane to pane "com.apple.preference.keyboard" end tell tell application "System Events" if UI elements enabled then tell tab group 1 of window "Keyboard" of process "System Preferences" -- replaced next line because it stopped working the next day. WAT? --click checkbox "Use all F1, F2, etc. keys as standard function keys" click checkbox 1 end tell else tell application "System Preferences" set current pane ¬ to pane "com.apple.preference.universalaccess" display dialog ¬ "UI element scripting is not enabled. Check \"Enable access for assistive devices\"" end tell end if end tell tell application "System Preferences" quit end tell
Set up the Keyboard Shortcut to Toggle Function Lock
Open up your keyboard settings (again, Alfred is helpful). Go to the Keyboard Shortcuts tab and select Services on the left. Scroll to the bottom and you should see General > Function Toggle. I set my shortcut to ⌘+`.
I find it too bad that I have to go through such rigmarole to get a standard Ubuntu feature back (or standard keyboard feature, rather). But I feel that I am better for having had to figure it out.