Pass text input to Shell using automator.

Hello again Apple Community!


What I am trying to do is use automator to promt the user for information like a username and password and then pass that information through a shell command to create a generic keychain item.


What I have so far is an Automator "Ask for text" getting the username and the script I have so far is:


on run {input, parameters}

do shell script "security add-generic-password -a" & input & "-s servicename -w IAMZPASSWURD"

end run


But it will not take the input and include it in the shell script. Any ideas?

Posted on Jul 30, 2013 5:55 PM

Reply
3 replies

Jul 31, 2013 5:18 PM in response to richardsoper

I found the solution! It is a very very sublte mistake. Now Ive got it broken up into 4 chunks to build the command, though I'm sure it could be combined if needed.


Get username:


on run {input, parameters}


tell me to activate

display dialog "What is your username?" default answer ""


set input to text returned of result

return input

end run


Add username to shell command(I initially missed the space between the -a and the quote and the -w and the quote):


on run {input, parameters}

set thevariable to input

set theScript to "security add-generic-password -a " & thevariable & " -s keychainitemname -w "


return theScript

end run


Get password and add to end of command:


on run {input, parameters}

set theScript to input

tell me to activate

display dialog "What is your password?" default answer ""


set ACP to text returned of result

set keychaincan to input & ACP

return keychaincan as string

end run


Finally, send the Shell Command:


on run {input, parameters}



do shell script (input)

return input

end run



Hope this helps anyone trying to accomplish this same thing!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Pass text input to Shell using automator.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.