Modify preferences using Alfred+OsaScript

Since I start using OS X I’ve never been a “spotlight” user. Althought it is there and never really used it as my daily driver, for some time I used QuickSilver because when I was using Linux I used GNOME do, but then I switched to Alfred. The main reason is that is super fast and let me execute custom commands from a couple of key strokes.

Alfred have several features by default, like searching in files/folders (using spotlight API) or the Web by opening the browser and Google to the search terms. The calculator, and one of the things that I use all day every day: The Clipboard, super useful.

But today I’m going to talk about the Workflows, workflows let you create custom commands, like the one that let me tweet from alfred, open a custom page by using a keyword, tweet the itunes current song and today I made a small script to switch my settings in Mission Control to disable and enable hot corners.

First of all, the hot corners feature is a must to me, I’ve used it when I was using Linux with Compiz, is super fast to have all open windows and choose the one I want (although in OS X when you are in “exposé” mode it would be great to let you type and filter with using the application name). So, I use hot corners a lot. I also use virtual machines, and I use them in full screen, so when the mouse points to the hot corner then it enters in exposé mode, the worse is that when I click again in the virtual machine the mouse points to the hot corner again and the loop beings.

So, when using the virtual machine (Windows to play or to do some windows exclusive thing), I have to disable hot corners and when I finish re-enable hot corners which is a PITA when you have to do it continuously.

So, I made this custom command, which is basically osascript launched with an Alfred command

The Script

set settings1 to {"Mission Control", "-", "-", "Mission Control"} -- for example
set settings2 to {"-", "-", "-", "-"} -- for example

tell application "System Preferences"
    reveal pane id "com.apple.preference.expose"
    activate
    tell application "System Events"
        tell window "Mission Control" of process "System Preferences"
            click button "Hot Corners…"
            tell sheet 1
                tell group 1
                    if value of pop up buttons is settings1 then
                        set theSettings to settings2
                        set functionKeys to false
                    else
                        set theSettings to settings1
                        set functionKeys to true
                    end if
                    repeat with k from 1 to 4
                        set theValue to item k of theSettings
                        tell pop up button k
                            if value is not theValue then
                                click
                                click menu item theValue of menu 1
                            end if
                        end tell
                    end repeat
                end tell
                click button "OK"
            end tell
        end tell
    end tell
    quit
end tell

How does it looks?

Like this.

It have to open the preferences pane and move around the buttons and options but it does automatically, and in a couple of seconds 😉

At the end

So, as you can see the script is not dynamic, because I want to have hot corners disabled or enabled depending on what I need, but you can tweak it to use whatever you want.

That’s just an example, you can write your own even in other languages like PHP, BASH, Python or any other by using the appropriate interpreter. But please, don’t make a “Launch Nuclear Bomb” script and if you do it, share with the others 😉

 2,276 total views,  4 views today