Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rate Thread Display Modes
Old 01-11-2010, 12:29 PM   #1
anika123
All Star
 
Join Date: Sep 2006
Posts: 860
Getting password from keychain with applescript

I have been trying to get passwords from the keychain with apple script and have run into a few stumbling blocks, not really a surprise for me. This only has to do with simple Internet keychain items. Anyway, here is a list of problems. Any pointers are appreciated. Here is the script (code found here).

Code:
tell application "Keychain Scripting"
	launch
	tell current keychain
		tell (some Internet key whose name is "www.youtube.com"*)
			set myPW to password
		end tell
	end tell
end tell
return myPW
Problem 1

Here is how I am searching for the items at the moment: tell (some Internet key whose name is "www.youtube.com")

The problem I am running into here is that since July 09 or so Keychain has been adding the username of the account to the name. So for instance, the actual name in the keychain is "www.youtude.com (myloginname)".

Question, how do I find the key without explicitly adding the (myloginname)? I want to be able to find this key by highlighting the web site name and evoking a service menu item.

Problem 2

How can I eliminate the pop up dialogs that ask me if it is ok for the script to access my keychain? In my testing so far there are two times in which I have to choose OK in order to get one password.

Also, are any of these goals made easier with the app Security? I have played with that and it is faster but will not just spit out the password, say to a file or clipboard. It seems to want to give all the info except the password to a pipe. Otherwise the password prints out fine on stout.

Update: whoops. that is not the code. There is no * after "www.youtube.com"
__________________
Snow Leopard 10.6, MacBookPro1,1

Last edited by anika123; 01-11-2010 at 02:03 PM.
anika123 is offline   Reply With Quote
Old 01-11-2010, 04:05 PM   #2
tlarkin
League Commissioner
 
Join Date: Mar 2003
Location: Bay Area, CA
Posts: 11,352
You can try having a root level script run the security command to modify keychains. I have never had luck getting it to work and gave up on it.

Quote:
NAME
security -- Command line interface to keychains and Security framework

SYNOPSIS
security [-hilqv] [-p prompt] [command] [command_options] [command_args]

__________________
sudo make me a sammich
tlarkin is offline   Reply With Quote
Old 01-12-2010, 05:13 PM   #3
anika123
All Star
 
Join Date: Sep 2006
Posts: 860
Quote:
How can I eliminate the pop up dialogs that ask me if it is ok for the script to access my keychain? In my testing so far there are two times in which I have to choose OK in order to get one password.

Turns out this part is pretty darn simple. Under keychain.app there are settings for each key that allow you to specify apps that are allowed to access a particular key. In this case adding "/System/Library/ScriptingAdditions/Keychain Scripting" to the allowed apps makes all the pop-ups go away and the script happily hands back my password.
__________________
Snow Leopard 10.6, MacBookPro1,1
anika123 is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 08:41 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.