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

10.5: Use Caps Lock to send keystrokes via AppleScript System 10.5
I finally had that eureka moment, on how to detect Caps Lock using Applescript, while trying to help out on this forum thread about auto-logging out from a Mac.

The Applescript calls KeyboardViewerServer.app, and checks the value of the CAPS key via the Keyboard Viewer window. A return value of 1 means the Caps Lock key is down, and a return of 0 means it's up. The really strange -- but good -- thing is that even if the Keyboard Viewer window is not actually visible, the value still gets returned. (If it pops up the first time you run the script, just close its window). Here's a test script to demonstrate how it works: Save the code as an application with the Stay Open box checked, then run it. TextEdit should launch, and when you press Caps Lock, the digit 1 will start appearing on your screen. Press it again, and the numbers will stop. This one is used to send the keystroke "1" to World of Warcraft as long as Caps Lock is down. Obviously, you can send whatever keystroke you want by modifying the script.

[robg adds: This worked for me when I tested it.]
    •    
  • Currently 1.80 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[14,652 views]  

10.5: Use Caps Lock to send keystrokes via AppleScript | 10 comments | Create New Account
Click here to return to the '10.5: Use Caps Lock to send keystrokes via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Use Caps Lock to send keystrokes via AppleScript
Authored by: NovaScotian on Feb 12, '08 08:53:59AM

All I get (OS X 10.5.2, dual-core G5) is a statement that the KeyboardViewerServer can't be found even though I can see it running in the Activity Monitor and it has a plist in ~/Library/Preferences folder. My Keyboard Viewer (US) window appears as it should if I invoke it from the Language dropdown menu but it doesn't respond to a command to activate.



[ Reply to This | # ]
10.5: Use Caps Lock to send keystrokes via AppleScript
Authored by: dietermay on Feb 13, '08 04:10:18AM

change the line
tell application "KeyboardViewerServer" to activate
to
tell application "/System/Library/Components/KeyboardViewer.component/Contents/SharedSupport/KeyboardViewerServer.app" to activate



[ Reply to This | # ]
Anyone know how to set the blink the caps lock light?
Authored by: mal0rd on Feb 12, '08 08:59:55AM
I tried doing:
set value of checkbox "⇪" of window 1 of application process "KeyboardViewerServer" to 1
and
keystroke "⇪"
but it seems to have no effect. I read the forum comments but they didn't help. I used to do this in Linux to notify me of a new message and it would be great to get this feature again.

[ Reply to This | # ]
Anyone know how to set the blink the caps lock light?
Authored by: mark hunte on Feb 12, '08 12:04:17PM

Sorry, not sure what you are trying to do?

---
mh



[ Reply to This | # ]
Anyone know how to set the blink the caps lock light?
Authored by: mark hunte on Feb 12, '08 12:06:40PM

Ah.. I read your post wrong, yes I tried this when I first looked at the caps thing. I have not found a way to get the value to change.



---
mh



[ Reply to This | # ]
10.5: Use Caps Lock to send keystrokes via AppleScript
Authored by: linux454 on Feb 12, '08 09:03:01AM

I have the same issue as the first poster.



[ Reply to This | # ]
10.5: Use Caps Lock to send keystrokes via AppleScript
Authored by: mark hunte on Feb 12, '08 11:44:50AM

If The Script can not find the "KeyboardViewerServer.app"

Use the browse Button to select the KeyboardViewerServer.app. You will find it here.

"/System/Library/Components/KeyboardViewer.component/Contents/SharedSupport/"




---
mh



[ Reply to This | # ]
10.5: Use Caps Lock to send keystrokes via AppleScript
Authored by: mark hunte on Feb 12, '08 11:57:53AM

Also I meant to mention Most of the keys now return a value...

---
mh



[ Reply to This | # ]
10.5: Use Caps Lock to send keystrokes via AppleScript
Authored by: mark hunte on Feb 18, '08 01:13:53PM

I Just wanted to Add,

Being able to detect the status of the Caps Lock, means you can use it's state to do many things, not just send keystrokes.
Another example would be use it as a toggle to pause/run a script/application or toggle the actions of part of a script/application...





---
mh



[ Reply to This | # ]
10.5: Use Caps Lock to send keystrokes via AppleScript
Authored by: Sesquipedalian on Jul 21, '09 07:38:42PM
For me, using window 1 of application process "KeyboardViewerServer" did not work, and Script Editor threw an error. However, first window of application process "KeyboardViewerServer" did work. I suppose something is wrong in an Applescript dictionary somewhere.

[ Reply to This | # ]