5 Replies Latest reply: Feb 17, 2013 10:06 AM by Pierre L.
wrignj08 Level 1 Level 1 (0 points)

Hey All,

 

I would like an applescript that would get the command tab (application switcher) up and hold it there until the mouse was clicked. Currently i have the below script but it ends at a set amount of time not a click. I would be very pleased if some one could help me out.

 

tell application "System Events"

key down command

keystroke tab

key code 123

delay 2

key up command

end tell

 

Thanks


Mac OS X (10.7.2)
  • 1. Re: Command Tab AppleScript
    Pierre L. Level 4 Level 4 (3,860 points)

    The following script seems to do what you are asking for:

     

    tell application "System Events"

        key down command

        keystroke tab

        key code 123

        repeat while (exists list 2 of process "Dock")

            delay 0.1

        end repeat

        key up command

    end tell

     

    Hope it can help.

  • 2. Re: Command Tab AppleScript
    sterlingfive Level 1 Level 1 (0 points)

    I had the same exact problem and this solution works for me too.  One problem though...  I save it as an application to be ran with a shortcut from my graphics tablet and the first time I ran it, the applescript application didn't quit itself properly and continued to hold down command.  I had to force quit it.  Is there a reason that would have happened?  Thank you so much for providing the script, other than that issue which maybe was a fluke, it seems to do exactly what I needed.

     

    Oh one more thing.... is there a way to make it so the applescript application doesn't show up in the switcher?

  • 3. Re: Command Tab AppleScript
    Pierre L. Level 4 Level 4 (3,860 points)

    Even when saved as an application, the script should work as expected. Of course, don't save it as a stay-open application. Also, be sure to have enabled access for assistive devices in the Accessibility System Preference pane.

     

    On the other hand, it's not necessary to save the script as an application in order to run it with a shortcut, you could use FastScripts (free for up to 10 keyboard shortcuts) for that.

  • 4. Re: Command Tab AppleScript
    sterlingfive Level 1 Level 1 (0 points)

    I just checked out fastscripts.  Seems to work pretty well.  I guess it solves the issue of needing to hide the application from the dock and application switcher.  I did have one more instance of the command key getting stuck down.  It happened after I ran the script several times in short succession.  I was just testing it and then command was stuck down.  I will keep an eye on it and se if there is any sort of pattern to the problem.  Hopefully, it doesn't happen again at all.  Or it could be a conflict with something else, just not sure what yet.  Anyway, it's working better than my last solution of using a delay in the script and the fastscripts app is really cool too, I'm sure I'll be using it for more of my scripts.  Thanks for all the tips, Pierre.

  • 5. Re: Command Tab AppleScript
    Pierre L. Level 4 Level 4 (3,860 points)

    My pleasure. Thanks for your feedback.