1

I'm having a pretty basic shell script that's supposed to run at user login. To achieve this, I followed the guide for Automator from the first answer in this topic: Running script upon login mac

But somehow nothing happens. I also tried to create an application using the script editor with do shell script /blabla/git_credentials.sh which responded with a permission denied.

I don't see whats wrong here.

Oh, here's the script:

echo ""
echo "Setup Git Credentials"
echo "*********************"
echo "Please enter your first name: "
read fname
echo "Please enter your last name: "
read lname
echo "Please enter your mail address: "
read email
git config --global --remove-section user
git config --global user.name "$fname $lname"
git config --global user.email $email
echo "Credentials set." 

Edit: I just found out that the script is being run at login, but it neither opens up a terminal nor waits for my user inputs, I have just an empty Git config after every startup. I 'achieved' this using the script editor with do shell script "$HOME/git_credentials.sh" and saving it as an application, then putting it into the login items.

3
  • Seems like a strange way to use Automator. Isn't it better to get the input (name, email) within automator, using a nice text box which can be edited and then just call git directly? Commented Sep 17, 2013 at 14:45
  • Ok Thanks, I'll give it a shot, even though I've never used Automator before. Do you conincidentally have useful link that helps me getting into it? Commented Sep 17, 2013 at 15:10
  • No, I've only used it once or twice. Google will give you a fair few hits I would imagine. Commented Sep 17, 2013 at 15:14

3 Answers 3

3

The problem is that your Automator's shell script isn't connected to STDIN (i.e. your keyboard). It may run the shell script, but there's no way to pass it input since there's no terminal.

What you need to do is run the Automator action: Ask for Text to get your input.

What I found I had to do was Ask for Text, and then Set the Value of the Variable. I do this for each variable I want as input.

Once I get all of the variables I want, I then run Get the Value of the Variable for each of the variables. This puts the variables into $* for the shell script to pull up.

Now, you can execute the Automator action Run Shell Script with Pass Input as arguments. You can refer to them as $1, $2, etc.

I suggest to try this with a simple script and see if it then works. The problem is that the whole thing may execute in a sub-shell, so once the automator action ends, you lose the values of the variables you've set. I simply don't have enough experience with Automator to know exactly how it works.

Sign up to request clarification or add additional context in comments.

1 Comment

Cheers for your answer, this helps me getting started.
1

I suspect you script is not currently executable.

Try fixing this by running: chmod +x /blabla/git_credentials.sh

or

chmod 755 /blabla/git_credentials.sh

1 Comment

Does this also apply for the application created with Automator?
0

Or you are missing #!/bin/bash at the top of your script? Or is this just a part of it?

9 Comments

No that's the whole script. You have to select the shell in Automator, so does this still make sense? Anyway, I tried to add the line at the top und save the application in Automator, but I still can't run it.
Oh, ok. Well, permission denied would point to the answer by Andrew Stubbs.
I tried to set the rights via chmod on the application I created with Automator - no success. I also tried to use the launchd solution of my link with a script that's had the chmod treatment - no success.
Weird. Does the script work when you just run it in Terminal with $blabla > ./git_credentials.sh ?
Yes it does, works fine. I just found out that the script is being run at login, but it neither opens up a terminal nor waits for my user inputs, I have just an empty Git config after every startup.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.