INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Mac Media Keys Fix  (Read 1413 times)

dfortney

  • Galactic Citizen
  • ****
  • Posts: 310
Mac Media Keys Fix
« on: September 07, 2018, 02:11:37 pm »

Would it be possible for you guys to run this apple script right after launch on a Mac or possibly a way to run any external app or script on launch?  This script fixes the issue with Media Center not grabbing the media keys on launch and just toggles the 'Use F1 keys...' option under Keyboard preferences on and off again.

tell application "System Preferences"
   reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell

tell application "System Events" to tell process "System Preferences"
   repeat until exists tab group 1 of window 1
   end repeat
   click checkbox 1 of tab group 1 of window 1
   delay 1
   click checkbox 1 of tab group 1 of window 1
end tell

quit application "System Preferences"

Logged

dfortney

  • Galactic Citizen
  • ****
  • Posts: 310
Re: Mac F Keys Fix
« Reply #1 on: September 07, 2018, 02:17:35 pm »

actually I just added a call to launch media center before running the f key toggle.  so anyone having this issue just create this as an app in script editor and run it to launch media center instead of the media center app itself...

tell application "Media Center 24" to activate

delay 1

tell application "System Preferences"
   reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell

tell application "System Events" to tell process "System Preferences"
   repeat until exists tab group 1 of window 1
   end repeat
   click checkbox 1 of tab group 1 of window 1
   delay 1
   click checkbox 1 of tab group 1 of window 1
end tell

quit application "System Preferences"
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Mac F Keys Fix
« Reply #2 on: September 07, 2018, 02:26:18 pm »

I was doing some research about this because I was curious about using a "defaults write" command instead of having to "hack" using AppleScript which relies upon the layout of the preferences pane.  Imagine my surprise when I found this application that automatically switches your F key preferences based on what program you are running!

https://github.com/Pyroh/Fluor

I have not used it, installed it, or tested it.  I just found it and thought dfortney or others might find it useful.

Brian.
Logged

dfortney

  • Galactic Citizen
  • ****
  • Posts: 310
Re: Mac F Keys Fix
« Reply #3 on: September 07, 2018, 03:19:10 pm »

I found it too and used it but it doesn't do what is actually needed in this case.  See it isn't a problem of having the right setting under keyboard prefs (unchecked) but that after launching media center even when it is unchecked you must check it and once again uncheck it to get it to register properly.  I think it must be a callback that isn't happening on launch from the os to tell media center (or any app perhaps) what the setting actually is.  I believe this applescript is the only way to fix this unless media center takes it internally to execute on their own during launch but of course using more appropriate API instead of hacking it as such.
Logged

dfortney

  • Galactic Citizen
  • ****
  • Posts: 310
Re: Mac F Keys Fix
« Reply #4 on: September 07, 2018, 03:22:55 pm »

oh one thing I forgot to mention above is after you save this apple script as an 'application' you must go to system pref -> security -> privacy -> accessibility and unlock for changes and then + to add this new app to the list of allowed apps.  what I did was remove the original media center icon from the dock and instead keep this application locked to the dock and before saving it in script editor you can actually steal the original media center icon file from within their package ->resources folder and drop it into the package within the editor so it looks like the original app icon.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Mac Media Keys Fix
« Reply #5 on: September 07, 2018, 06:50:22 pm »

Hmm, seems like strange behavior.  What are you trying to do with these keys?  I'm assuming use the "media keys" to do play/pause, track fwd/back, etc.

I have all of those mapped to other keys, using MC's key assignment file.  For example, <Command><up arrow> is Volume Up.  <Command><down arrow> is Volume Down.

If you like the media keys, I'm not trying to change your mind.  I just always found them to be in the "wrong place", so I did mappings that made sense to me.

Brian.
Logged

dfortney

  • Galactic Citizen
  • ****
  • Posts: 310
Re: Mac Media Keys Fix
« Reply #6 on: September 07, 2018, 08:30:24 pm »

yes, just trying to use them for what they represent.  nothing fancy here.  vol up down work correctly via menubus but play/pause etc doesn't work unless i toggle this setting in keyboard prefs after every relaunch of media center.  has been this way since version 20 or before if i remember correctly.
Logged
Pages: [1]   Go Up