Is there a way to trigger some apple script based on applications/events?
What I want to do is to increase brightness when I am running videos etc. fullscreen, and reduce it when I exit the fullscreen view of the player. I can use key code 113
and key code 107
in loop to adjust brightness I guess, but how to automate it based on application's fullscreen status?
Preferably I'd like to be able to specify the applications (like iTunes, VLC etc.) but just detecting fullscreen would do fine.
Best Answer
I'm using a little menubar program called ControlPlane.
It allows you to create "contexts". You define what evidence sources the program keeps an eye on, and when it detects the activation of some evidence source, it switches to a context and performs a set of actions that you've set it to do. It has a lot of actions to choose from, but if you don't find what you like, you can also set it to run an applescript that you've written, just remember to save the script as an application, for otherwise it will simply open the script as a text in Script Editor. I think you could try something like this:
I use ControlPlane in concert with a key binding program called BetterTouchTool.
If I wanted to have ControlPlane change the brightness level not whenever VLC is open, but whenever it's in fullscreen, I might first create the ControlPlane brightness action thing described above but set it to never look for evidence and change context spontaneously on its own. Instead, I could write an AppleScript which would command ControlPlane to toggle that context.
In BetterTouchTool, I could then select VLC as the application in question and create a new keyboard shortcut for it to override what it originally has. I think + F normally toggles fullscreen mode in VLC. In BetterTouchTool, you could assign + F to do multiple actions of your choice:
BetterTouchTool also has an action to change the display brightness so you can also just skip ControlPlane, but I explained the whole ControlPlane thing in case that you actually do want to automate something for some apps without having to press any keys yourself.
I'm assuming that you're on a laptop or an iMac, are you? Because these brightness commands don't work for external monitors.