Monday, July 26, 2021

#1 2021-06-12 12:45:07 pm

nigelheinsius
Member
Registered: 2011-03-27
Posts: 11

Storing a username and password via Applescript?

I want to write an Applescript library to access my MySQL on localhost so that I can simplify running such commands as:

Applescript:

set myResult to do shell script "/Applications/MAMP/Library/bin/mysql --host=localhost --user=root --password=pw -D 'books_db' -e \"SELECT title, author, publisher, length FROM books_list WHERE author LIKE '%" & searchResult & "%'\""

Is there a way to safely store the variables here (user, password) somewhere on the Mac? I thought there might be a way to get into Keychain Access, but looking in Script Debugger it doesn't look like it is scriptable.

The idea would be that on first run of any of the commands, it would check, set or get the variables for your database.

Any suggestions?


Filed under: mySQL, Libraries, passwords

Offline

 

#2 2021-06-12 06:47:16 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6677

Re: Storing a username and password via Applescript?

If you use my BridgePlus library, it has ASObjC commands for retrieving passwords from a keychain.

https://latenightsw.com/support/freeware/


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2021-06-13 01:03:54 pm

nigelheinsius
Member
Registered: 2011-03-27
Posts: 11

Re: Storing a username and password via Applescript?

Thanks Shane. I will have a look at this.

Offline

 

#4 2021-07-20 05:34:46 am

RIBA63
Member
Registered: 2021-07-19
Posts: 1

Re: Storing a username and password via Applescript?

You may want to try this :

First manually add an entry in your Keychain
Name : MyUserPW
Kind : application password
Account : sudo_name
Where : sudo_pw
Password : <enter your user password here>

Then run :
set pw to do shell script "security find-generic-password -a sudo_name -s sudo_pw -w"

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)