Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript say app names during Cmd + Tab

I'm writing a script for a speakable item that will let me switch applications without having to touch the computer, by invoking the Cmd+Tab functionality. So far, I have the following:


tell application "System Events"
     key down command
     key code 48
end tell

tell application "SpeechRecognitionServer"
     set userinput to listen for {"left", "right", "select", "cancel"} 
     if userinput = "left" then
          tell application "System Events"
               key code 123
          end tell
     else if userinput = "right" then
          tell application "System Events"
               key code 124
          end tell
     else if userinput = "select" then
          tell application "System Events"
               key up command
          end tell
     else if userinput = "cancel" then
          tell application "System Events"
               key code 53
          end tell
     end if
end tell


This code basically presses Command and taps Tab while keeping Command pressed, thus prompting the handy little window of what applications are open to pop up. I can then navigate (albeit slowly) using the 'left' and 'right' commands, and settle on a choice by saying 'select'; alternatively, I can cancel the process with the command 'cancel'.


However, this requires me to be present at the computer, or at least keep an eye on the screen, so that I know what application is currently selected. This defeats one of the two main reasons for having voice commands activated. These two reasons are 1) I am at my computer but my hands are busy, and 2) I am away from my computer. Forcing me to be present in order to switch applications clearly runs contrary to the second reason; in all the other speakable items I've created, I've worked in some sort of verbal feedback that lets me know what's going on so that I can operate my computer from across the room.


Thus, my question: is there a way to have AppleScript tell me what application is currently selected? I'm kind of new at AppleScript, and in any case I feel like the answer to this couldn't be found in the few areas I'm already familiar with (I mean, the little Cmd+Tab window isn't exactly an application, so I doubt I could get to its code via UI scripting).


Thanks!

MacBook Pro, OS X Mavericks (10.9.2)

Posted on Apr 16, 2014 7:26 PM

Reply
1 reply

Applescript say app names during Cmd + Tab

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.