1

I am trying to implement a "Command-tab" style setup that works only within a specific space. For most apps, "Ctrl-F4" which is "move focus to active or next window" works correctly, but for emacs/aquamacs it does not (as the keypress is absorbed by the app). (System Preferences->Keyboard->Shortcuts->Keyboard lists this option). I want this to go between the windows I've organised into a space as relevant, i.e. my R script, plots in X11 and in png/pdf format.

I can run an arbitrary applescript with fastscripts or other apps on a keypress. I therefore see two options:

  1. Tell the window manager directly to perform the move focus, WITHOUT going via a keypress
  2. Use a keypress but checking for aquamacs as the active window. On finding aquamacs, get a list of the processes in the current space and move to the next one. (checking for aquamacs seems wise as the default behaviour is likely faster than this lookup)

Searching for these behaviours is difficult, and the applescripts documentation is byzantine to a newbie, so I don't see how to achieve either of them.

1

See if invoking with System Events doesn't override the scope of emacs/aquamacs.

tell application "System Events" to key code 48 using {command down}

If that still doesn't help, you can trap for it:

tell application "System Events"
    set theName to name of the first process whose frontmost is true
    if theName contains "emacs" then
        set frontmost of item -2 of (every process whose visible is true) to true
    else
        key code 48 using {command down}
    end if
end tell
  • This is very helpful, thank you very much. It is indeed necessary to trap the system event. Unfortunately, even this doesn't quite work because C-F4 allows you to cycle through all windows by holding down the control key, whereas this applescript implementation of course only does the keypress once. Making it impossible to cycle through all windows, only switching between two. I'm beginning to fear that it would need a significant amount of work to implement this functionality! – Daniel Lawson Oct 3 '15 at 22:47
  • I may not understand your needs, fully, then. Are the windows you want to cycle through more than two? Are they from the same number of apps? You could have a script that cycles between apps, activating each in turn. – jweaks Oct 4 '15 at 4:24
  • I just want a "Cmd-tab" behaviour for a single space. I thought that the requested behaviour, which your script implements, would do it. As we've seen it didn't because I hadn't anticipated the importance of holding it down. – Daniel Lawson Oct 4 '15 at 18:52
  • So, the applescript solution did not solve my underlying problem, but I can solve this now. The application hyperswitch (bahoom.com/hyperswitch) puts the behaviour I wanted into Option-Tab. – Daniel Lawson Oct 17 '15 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .