Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: Use keyboard shortcuts to run arbitrary applications Desktop
I like to have a shortcut key to open up a new Terminal window or xterm. When I upgraded to Panther, iKey, which I'd used previously for this, didn't work for me, and Another Launcher was overkill. However, you can use the ScriptMenu and the Keyboard Shortcuts to achieve the same effect.
  1. Enable the script menu by executing (from the Terminal, or via the Finder in /Applications -> AppleScript)
    open "/System/Library/CoreServices/Menu Extras/Script Menu.menu"
  2. Create a script to do what you need using AppleScript Editor. My script (Terminal.applescript) looks like:
    
    ignoring application responses
      tell application "Terminal"
        activate
        do script ""
      end tell
    end ignoring
    
    You can modify the script as you need. For example, removing the do script line and changing Terminal to another application will just start another application.

  3. Compile the script (save it as a script with AppleScript Studio; it gets the extension .scpt) or use osacompile -o Terminal.scpt Terminal.applescript

  4. Move the script to your ~/Library/Scripts folder; it should now appear as one of the scripts.

  5. Go to the Keyboard & Mouse Preference Pane and add a keyboard shortcut for all applications for "Terminal."

  6. Login and logout and voila, arbitrary command run by keyboard!
Now if I could only get Terminal windows to arrange themselves more intelligently (place themselves in open space)...
    •    
  • Currently 1.75 / 5
  You rated: 1 / 5 (8 votes cast)
 
[28,011 views]  

10.3: Use keyboard shortcuts to run arbitrary applications | 31 comments | Create New Account
Click here to return to the '10.3: Use keyboard shortcuts to run arbitrary applications' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Key Xing is a lean and fast alternative
Authored by: opsotta on Nov 05, '03 11:31:09AM

I'm using Key Xing since Mac OS X v10.0. It has been updated for Panther and is lean, fast and powerful. And cheap!



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: DougAdams on Nov 05, '03 11:49:12AM
Additionally, have a look at Apple's AppleScripts for Terminal. There aren't a lot of scripts, but I think you'll find a hint on how to do your Terminal windows manipulating.

[ Reply to This | # ]
Arranging Terminal windows
Authored by: ubi on Nov 05, '03 12:13:51PM

You wrote: "Now if I could only get Terminal windows to arrange themselves more intelligently..."

I have a possible solution. Terminal.app supports Xterm escape sequences. Using these, I've written the following little C program (the pretty indenting of which the MacOSXHints formatter will now garble--sorry--but it's C so it will *still* compile :-] ):

/* --------------------- Begin xgeom.c ----------------------------- */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

main(int argc, char **argv)
{
int h=24, w=80, x=0, y=0;
if(argc>1)
{
if(argv[1][0]=='-')
{
printf("Usage: %s h [w [x [y]]]\n", argv[0]);
exit(1);
}
h = atoi(argv[1]);
if(argc>2)
{
w = atoi(argv[2]);
if(argc>3)
{
x = atoi(argv[3]);
if(argc>4)
{
y = atoi(argv[4]);
}
printf(";%dt", x, y);
}
}
printf(";%dt", h, w);
}
}
/* --------------------- End xgeom.c ----------------------------- */

Then I define the following (bash-style) aliases:

alias b='xgeom 23 166 1 352'
alias bl='xgeom 23 81 1 352'
alias br='xgeom 23 81 513 352'
alias f='xgeom 52 166 1 1'
alias l='xgeom 52 81 1 1'
alias r='xgeom 52 81 513 1'
alias t='xgeom 23 166 1 1'
alias tl='xgeom 23 81 1 1'
alias tr='xgeom 23 81 513 1'

for bottom, bottom-left, bottom-right, full-screen, left, etc. Now, when I want the terminal window I'm currently in to use the top-left quarter of the screen, I just type "tl" (and the return key of course) and it resizes and repositions itself there. These aliases are set for my 12" PowerBook (1024x768 pixels). You'll need to change them if your screen is different or you use a different font than I do (Monaco Regular 10-point), or a different-height Dock. But it's easy to experiment with xgeom.

Hope this helps.



[ Reply to This | # ]
Arranging Terminal windows
Authored by: stift on Nov 05, '03 12:32:32PM

how do i compile this ?



[ Reply to This | # ]
Compiling xgeom [Arranging Terminal windows]
Authored by: ubi on Nov 05, '03 01:24:27PM

Use gcc to compile. I believe it's on the Panther Developer Tools CD.

gcc -o xgeom xgeom.c

Then put xgeom somewhere in your shell's PATH.



[ Reply to This | # ]
Correction: Arranging Terminal windows
Authored by: ubi on Nov 05, '03 01:13:47PM

Just noticed that my C source didn't copy the escape sequences correctly. The two printf() calls should read as follows:

printf("^[[3;%d;%dt", x, y);
printf("^[[8;%d;%dt", h, w);

where ^[ represents a literal escape. You can enter this in vi by typing Control-V, then hitting the escape key. (Not sure how to do it in emacs.)



[ Reply to This | # ]
Arranging Terminal windows
Authored by: jaysoffian on Nov 05, '03 11:40:14PM
Hmm, gratuitous use of C if you ask me :-)
How about the following sh one-liner for xgeom?

#!/bin/sh
printf '^[[8;%d;%dt^[[3;%d;%dt' $@

You could also define this as shell function in the same place you're setting up your bash aliases.

---
j.


[ Reply to This | # ]

One-liner [Arranging Terminal windows]
Authored by: ubi on Nov 06, '03 12:29:23AM

Thanks for the tip. I never knew about printf as a sh/bash command. Cool. The only thing my C code does better is handle a variable number of arguments. Here's the suggested bash function:

function xgeom { printf '^[[8;%d;%dt^[[3;%d;%dt' $@ ; }



[ Reply to This | # ]
One-liner [Arranging Terminal windows]
Authored by: kmue on Nov 06, '03 04:22:13AM
Nice! Its easier to cut 'n pasta if you use escape codes:

xgeom() { printf '\033[\033[8;%d;%dt\033[\033[3;%d;%dt' $@; }


[ Reply to This | # ]
Code garbling
Authored by: ssevenup on Nov 06, '03 02:34:19PM

The forums will protect your code format if you do this...

To protect special characters such as \, <, and >, please use the [code] and [/code] tags around any XML, UNIX code, AppleScripts, or other code fragments in your submission! Yes, those are square brackets, and remember to set the post mode to 'HTML formatted,' too.

It's displayed along with the Post a Comment window here as I post this.

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: DigiH on Nov 05, '03 12:56:06PM

Hi,

I really like the idea of this tip, but somehow it doesn't work for me.

The Script turns up fine in the Script Menu, keyboard shortcut is assigned, but nothing happens. I made sure that the naming matches, tried different shortcuts, logging out and in again, but no luck.

Any ideas? Do I need to turn on any other settings?



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: acalado on Nov 05, '03 01:01:15PM

Same problem here. Also would like to map a keyboard shortcut to "Lock Screen" from the Keychain menu. No luck there either.

Andy



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: u2mr2os2 on Nov 28, '04 01:53:34PM
Get the free utility Sizzling Keys for iTunes at www.yellowmug.com. One of the extras is it lets you assign a key to do exactly that. It's a nifty iTunes controller as well, but you could turn most all that off if you want.

[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: brain13 on Nov 05, '03 01:10:48PM

Everything works fine until i try to use the shortcut and nothing happens at all....its the same for any shortcut i have created....

I am using a fresh panther install on a 17" ai pb....

I wish this worked...damn!



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: DigiH on Nov 05, '03 01:17:49PM

Me again,

Same here, no shortcut seems to work. Also on a PB, could this be the problem?

Anyone else with a PB who can get it to work?



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: acalado on Nov 05, '03 01:20:23PM

I'm using an iBook 700 with no luck.

Andy



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: diamondsw on Nov 05, '03 04:46:38PM

And I'm using an iBook 800 with no luck. Grrrr...



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: windrag on Nov 05, '03 07:05:29PM

I've been experimenting with the Keyboard Shortcuts assignment. I can't get it to work for anything on the right side of the menu bar, like View as Analog under menu bar clock, but it works with Show Clipboard from the Edit menu (both shortcuts assigned to Finder, not All Applications.)

I tried launching a script from the ~/Library/iTunes/Scripts directory, and the shortcut appears in the menu (only if it is in the first level, not a subfolder) and the menu darkens when I use the shortcut, but the script fails to launch. Using the mouse on the menu item works as expected.

---
Ryk A. Groetchen
700MHz iBook 16 VRAM G3
640MB RAM
OS X 10.3



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: DougAdams on Nov 06, '03 08:09:41AM

Just a shot in the dark, but is "Turn on full keyboard access" checked in Keyboard Shortcuts?



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: ClarkGoble on Nov 05, '03 01:21:07PM

Using iKey or Quickkeys does this a lot easier and more flexible. Check them out. I use iKey although it is shareware.



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: Cantus on Nov 05, '03 02:08:04PM
save it as a script with AppleScript Studio

I believe he means Script Editor and not AppleScript Studio. Script Editor is an application, AppleScript Studio is not. Script Editor can be found in /Applications/AppleScript.

And there is no need to run the first command mentioned to enable the Script Menu. In 10.3 (and this is a 10.3 hint) under /Applications/AppleScript there is an application called "Install Script Menu." When you launch this application, it will install the Script menu for you.

[ Reply to This | # ]

10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: choltz on Nov 05, '03 02:55:39PM

Not necessarily a PB problem. I am using an 800MHz quicksilver desktop and cannot get the keyboard shortcut to invoke the script either.



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: dpwk on Nov 05, '03 09:03:30PM

another datum: if you click on the scripts menu (to drop the menu) and hit the key command, the menu item for the script will blink, and the Finder will reveal the script. The script does not run, however.

hrmph!

(it's not working on my Tibook either)



[ Reply to This | # ]
"Turn on full keyboard access"
Authored by: DougAdams on Nov 06, '03 08:12:31AM

For those having problems -- don't know if this has been suggested -- is "Turn on full keyboard access" checked in Keyboard Shortcuts? The shortcuts work through GUI scripting, and that's what makes menu items accessible.



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: explosivo on Nov 06, '03 09:27:15AM

Doesn't work on my G4 Dual 1GHz or PowerBook 867... This would be a fantastic feature if it worked. I also noticed that if you create a shortcut for "Away" you'll see the shortcut in your iChat menu.

I'm always open to ways of eliminating daemon processes like iKey... Apple, are you listening? Please complete this feature!



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: formido on Nov 13, '03 11:28:52PM

I don't think this works in any useful fashion. User defined keyboard shortcuts only work on the front application. Unfortunately, the script menu (and the other menulets on the right side of the menu bar) are run by SystemUIServer. The only way it can receive a keyboard shortcut event is if you've clicked on the right side of the menu bar so that SystemUIServer becomes the front application. That works--try it and see--but it's not especially helpful.



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: jweaks on Mar 26, '04 12:40:22AM

This old hint has been denied by several responses, including my own experience. Can we get some confirmation on how to make this work? If it doesn't work, why is this tip still up here?
Is there any way to run a script or applet via the Keyboard Shortcuts option in the Keyboard Preference panel?



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: snaab on Feb 11, '05 12:46:49PM

This hint STILL only works halfway - the script works as advertised, but the keyboard shortcut produces no results. How can this be done using a keyboard shortcut??



[ Reply to This | # ]
Use Quicksilver
Authored by: procon on Apr 05, '05 08:07:58PM

Thanks to everybody who troubleshot this problem and figured out why keyboard commands would not work. Instead of keyboard shortcuts I use Quicksilver to trigger my scripts and it works flawlessly.

-Ari



[ Reply to This | # ]
10.3: Use keyboard shortcuts to run arbitrary applications
Authored by: telegramsam on Jul 01, '05 07:28:51PM

If you restart the machine, this hint should work.

---
What is signature?



[ Reply to This | # ]
Try Quicksilver
Authored by: Sham The Sam on Apr 26, '07 01:45:54PM

If anyone is still coming across this hint in the year '07 (or possibly beyond?), try taking a look at Quicksilver. After lots of frustrating research, I finally got it through my head that keyboard shortcuts for all applications cannot trigger Applescripts (at least in Tiger). However, with Quicksilver running, it can intercept your shortcut commands no matter the foremost application and can set in motion any Applescript that you want. Good luck out there.



[ Reply to This | # ]