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

Use AppleScript for a Virtual Numpad System
The keyboards on Mac notebooks, and now desktops, too, have no number pad. It used to be that notebook keyboards had a numlock key, and you could use the letter keys on the right hand side of the keyboard as a number pad, but that feature seems to have vanished. It can, however, be brought back with AppleScript. [crarko adds: You can get it by pressing and holding the 'fn' key, which is also cumbersome.]

The code given below will let you type as if this numpad existed. It will convert the letters into the corresponding numbers, and copy the result to the clipboard. When you need a numpad, just switch to this program, and then back to your original, and paste. Also, you can type normally by typing " " (double-space). Use that to switch to text mode, and again to switch out. For example: "jkl jkl jkl" will produce "123jkl123". If you use triple-spaces, one space will be left ("123 jkl 123"). So, you could type this: " My favorite number is jkluio789 ." and get "My favorite number is 123456789." Also, keys that do not represent any number will remain unchanged. Here's what each key does [crarko adds: Seeing the picture included in the download below will make this clearer]:
U=4 I=5 O=6 P=+
J=1 K=2 L=3
M=0 ,=00
7, 8, and 9 stay the same.
Normally, numpad keys aren't staggered, so this takes a little getting used to. But, I still find it a lot faster than the row of numbers at the top.

set toQuit to false
repeat while toQuit is false
 set dd to display dialog "Enter text..." with title "Numpad" buttons {"Quit", "Continue"} default button 2 default answer ""
 set ddText to text returned of dd as string
 set ddBtn to button returned of dd as string
 if ddBtn is "Quit" then set toQuit to true
 if ddBtn is "Continue" then
  set oldDel to AppleScript's text item delimiters as string
  set AppleScript's text item delimiters to "" as string
  set chars to items of ddText as list
  set AppleScript's text item delimiters to oldDel as string
  set nums to chars
  set sp to false
  set spSet to false
  set spUnSet to false
  considering case
   set valNum to 1 as integer
   repeat with val in nums
    if spSet is true then
     set spSet to false
     set valNum to valNum + 1
    else
     if spUnSet is true then
      set spUnSet to false
      set valNum to valNum + 1
     else
      if sp is true then
       if (val as string) is " " then
        if (item (valNum + 1) of nums) is " " then
         set sp to false
         set spUnSet to true
        end if
       end if
       set valNum to valNum + 1
      else
       if (val as string) is "u" then set item valNum of nums to "4"
       if (val as string) is "i" then set item valNum of nums to "5"
       if (val as string) is "o" then set item valNum of nums to "6"
       if (val as string) is "p" then set item valNum of nums to "+"
       if (val as string) is "j" then set item valNum of nums to "1"
       if (val as string) is "k" then set item valNum of nums to "2"
       if (val as string) is "l" then set item valNum of nums to "3"
       if (val as string) is "m" then set item valNum of nums to "0"
       if (val as string) is "," then set item valNum of nums to "00"
       if (val as string) is " " then
        if (item (valNum + 1) of nums) is " " then
         set sp to true
         set spSet to true
        end if
       end if
       set valNum to valNum + 1
      end if
     end if
    end if
   end repeat
  end considering
  set numsText to nums as string
  if numsText contains " " then
   set oldDel to AppleScript's text item delimiters as string
   set AppleScript's text item delimiters to " " as string
   set num to 1
   set sps to (count text items of numsText) as integer
   set numsText2 to "" as string
   repeat with num from 1 to sps
    set numsText2 to (numsText2 & text item num of numsText) as string
    set num to num + 1
   end repeat
   set AppleScript's text item delimiters to oldDel as string
  else
   set numsText2 to numsText
  end if
  set the clipboard to numsText2
 end if
end repeat


[crarko adds: When trying the examples, you need to actually type the text into the entry box; copy and paste didn't always work. It takes a few minutes to get used to the spaces to change modes, but it does work. The source code, a compiled version of the app, and a picture of the virtual keypad are mirrored here.]
    •    
  • Currently 2.04 / 5
  You rated: 1 / 5 (27 votes cast)
 
[17,558 views]  

Use AppleScript for a Virtual Numpad | 10 comments | Create New Account
Click here to return to the 'Use AppleScript for a Virtual Numpad' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use AppleScript for a Virtual Numpad
Authored by: brh on Jul 22, '10 11:25:58AM

You can't necessarily get it by pressing and holding the fn key. For instance, this works on my first-gen Macbook (which, actually has a true numlock feature as well) but it definitely does not work on my first-gen (3 battery) wireless aluminum keyboard.



[ Reply to This | # ]
Use AppleScript for a Virtual Numpad
Authored by: nathanator11 on Jul 22, '10 05:22:24PM

fn certainly doesn't work on my black MacBook (the last version before they went to the unibodies).



[ Reply to This | # ]
Use AppleScript for a Virtual Numpad
Authored by: nathanator11 on Jul 22, '10 05:25:32PM

Also thought I should add a rather obvious safety tip:
Before using this for something sensitive (like a credit card number), keep in mind the fact that this will be stored right in your clipboard until you copy something else, and until you restart if you have any kind of a clipboard manager.



[ Reply to This | # ]
Use AppleScript for a Virtual Numpad
Authored by: davidzilla27 on Jul 22, '10 10:21:34PM

The fn-key works on all Macbooks as far as I know, but it relies on the installation of KeyRemap4Macbook. Get it, it's an excellent piece of software!



[ Reply to This | # ]
KeyRemap4Macbook
Authored by: MtnBiker on Sep 09, '10 10:29:20AM

Thanks for this suggestion. This donation ware product worked out of the box. I've missed this feature for the at least two years since I replaced my G4 laptop.

And the program has many other options which I've yet to explore.

---
Hermosa Beach, CA USA



[ Reply to This | # ]
Use AppleScript for a Virtual Numpad
Authored by: lsequeir on Jul 23, '10 08:01:31AM

I believe there is a simpler and more effective solution than using an Applescript and then copy and paste.
Using a free utility like Ukelele, one can easily create a new keyboard layout - call it "Numeric", and make it the way you want it - just decide what the output of each required key in keyboard should be.
Place this in ~/Library/Keyboard Layouts.
Then activate the "Show keyboard and character viewer in menu bar" in System Preferences->Keyboard.

No, after you log out and back in, you have almost the equivalent of the old "num lock" key: just go to the menu bar and switch back and forth between the normal and the numeric keyboard. The numeric keyboard will be an actual keyboard, entering content directly into any application you want, not a middleman script followed by copy and paste.

Chances are a good enough keyboard layout may exist already.

---
Luís



[ Reply to This | # ]
Use AppleScript for a Virtual Numpad
Authored by: lsequeir on Jul 23, '10 10:18:43AM

I have tried my own proposed "solution" and:
1) there is no need to logout and login - the new keyboard layout is immediately available under System Preferences->Language & Text

2) it works :-)


---
Luís



[ Reply to This | # ]
Use AppleScript for a Virtual Numpad
Authored by: gmachen on Jul 23, '10 10:43:09AM

I use QuicKeys to re-map keys to behave just like the former good ol' embedded numeric keypad. No switching contexts or any other complications; it "just works." However, QuicKeys (or any other command-key assignment utility) cannot incorporate the fn key as a modifier; there's something funky about the fn key technically (it was once explained to me by a shareware programmer, but I've forgotten the details). So I just use the Ctrl key; it's easy to adjust to it in short order. (If you orient yourself by resting your pinky on the fn key, your ring finger naturally is where it needs to be for the Ctrl key.) There's probably a way also to duplicate the NumLock key functionality with QuicKeys (involving some multi-step macro with if-then dependencies), but I haven't ever needed it, so I never tried constructing one.



[ Reply to This | # ]
Use AppleScript for a Virtual Numpad
Authored by: dkk on Jul 30, '10 11:41:02AM

I had an old G5 imac that went belly-up. Rather than try to repair it (and since the future was all intel), I purchased a new intel imac. I noticed that the new system had no number pad on the keyboard. So, I hooked up the old keyboard to the new imac.

Guess what? It works, and I now have a number pad on an intel imac. I realize that this solution may not work for everyone, but if you have an old keyboard, you may want to give it a try .

Edited on Jul 30, '10 11:59:39AM by dkk



[ Reply to This | # ]
Use AppleScript for a Virtual Numpad
Authored by: kylecara on Jul 30, '10 08:05:04PM

Any tips of how to go about with that? I tried to create any type of shortcut key, but since I couldn't find any command for or way to reference the NumPad numbers, I wasn't able to.



[ Reply to This | # ]