Only Show Open Applications In The Dock

Description

Beginning AppleScripter Melissa wrote in with this question:
Using the terminal commands in this article, I've made Automator apps. One to do each command. I'd like to combine them into one. My thought was to do an if-then. If this script is currently true, then run the command to make it false. And vice versa. I've tried Googling a few things to figure out how, but to no avail.
I thought this would be a really useful one to whip up and especially fun for all you Alfred and FastScripts users to use a keyboard shortcut so that you can focus and streamline your Dock to only show the Apps you're currently using. This simple AppleScript lets you only show open Applications in the Dock -- and toggle it back to normal whenever you like! It looks to see whether the Dock is currently displaying all items or just the running applications, toggling it to the opposite value and restarting the Dock to display the changes. If this is your first time running the script, it creates the value needed so that the script doesn't fail with an error. Check out the annotations inside the script for more details on how it works -- and I hope you enjoy it!

Alfred 1 Extension

For all you Alfred users, here's a link to a downloadable extension to get you going.

The Code

(*
◸ Veritrope.com
TOGGLE SHOWING ONLY OPEN APPLICATIONS IN THE DOCK
VERSION 1.0
June 28, 2012

// UPDATE NOTICES
     ** Follow @Veritrope on Twitter, Facebook, Google Plus, and ADN for Update Notices! **

// SUPPORT VERITROPE!
     If this AppleScript was useful to you, please take a second to show your love here:
     http://veritrope.com/support

// SCRIPT INFORMATION AND UPDATE PAGE
    http://veritrope.com/code/Only-Show-Open-Applications-In-The-Dock

// REQUIREMENTS
     More details on the script information page.

// CHANGELOG
    1.0  Initial Version

// TERMS OF USE:
     This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

     To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.


*)


(*
======================================
// MAIN PROGRAM
======================================
*)

-- RESET THE VALUE BEFORE RUNNING
set current_Value to ""

-- ENCLOSING THIS IN A 'TRY BLOCK' LETS THE SCRIPT WORK
-- IF THERE ISN'T ANY VALUE FOR "com.apple.dock static-only"
try
   
    -- CHECKS TO SEE IF THE VALUE EXISTS
    set current_Value to (do shell script "defaults read com.apple.dock static-only")
   
    -- "1" MEANS DOCK IS IN 'OPEN ITEMS ONLY MODE'
    -- "0" MEANS DOCK IS THE DEFAULT DISPLAY MODE
    -- A MISSING VALUE ERROR WILL EXIT OUT FROM THIS 'TRY BLOCK'
   
    if current_Value is "1" then
        -- DOCK IS IN 'OPEN ITEMS ONLY MODE' / TOGGLE BACK TO NORMAL
        do shell script "defaults write com.apple.dock static-only -bool FALSE"
    else
        if current_Value is "0" then
            -- DOCK IS IN THE DEFAULT DISPLAY MODE / TOGGLE TO 'OPEN ITEMS ONLY MODE'
            do shell script "defaults write com.apple.dock static-only -bool TRUE"
        end if
    end if
   
    -- RELAUNCH THE DOCK TO SHOW THE CHANGE
    do shell script "killall Dock"
end try

-- IF YOU'VE NEVER RUN THIS BEFORE, CREATE THE VALUE IN OPEN ITEMS ONLY MODE'
if current_Value is "" then
    do shell script "defaults write com.apple.dock static-only -bool TRUE"
    do shell script "killall Dock"
end if

4 Responses to “Only Show Open Applications In The Dock”

  1. Pedro September 9, 2012 at 12:26 am #

    Installed as an Alfred extension, added a keyword. Alfred finds the command but pressing return does nothing – it just sits there…

    Any ideas, anyone?

    • Justin Lancy September 9, 2012 at 1:02 am #

      Oops- Forgot to uncheck a box!

      Uploaded a new version which (hopefully) corrects the issue. Working now?

      • Pedro September 9, 2012 at 1:18 am #

        Works perfectly! And very useful. Thx, Justin.

  2. Francesco September 9, 2012 at 6:14 am #

    Just installed the extension and it work perfectly. Thank you, you’re awesome man 🙂