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


Click here to return to the 'AppleScripting the Keychain menu' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
AppleScripting the Keychain menu
Authored by: waboom on Nov 07, '06 05:53:50PM
There is a way to script the keychain menu, but it's not through the Keychain Access application. Instead, you have to go through the UI Server, which controls all of the "menu extras" menus. Normally, you can find a particular menu extra by it's description ("iChat menu extra", for example.) However, the keychain menu extra does not register a description for itself, so if you want to access it via AppleScript, you have to do a bit more of a "kludgy" search. In this example, the script clicks on each menu extra, and looks at the first menu item. If the name of the item is "Lock Screen", then it clicks it. Note that UI Scripting has to be enabled for this to run (System Preferences->Universal Access->Enable access for assistive devices.)
activate application "SystemUIServer"
tell application "System Events"
	tell process "SystemUIServer"
		repeat with i from 1 to number of menu bar items of menu bar 1
			tell menu bar item i of menu bar 1
				click
				try
					if name of menu item 1 of front menu is "Lock Screen" then
						click menu item "Lock Screen" of front menu
						exit repeat
					end if
				end try
			end tell
		end repeat
	end tell
end tell


[ Reply to This | # ]
AppleScripting the Keychain menu
Authored by: jctull on Dec 06, '06 02:40:03PM

I knew someone else would have worked this out for me. Excellent!



[ Reply to This | # ]