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.

Community
  • 1
  • 1
DenverCoder21
  • 879
  • 3
  • 16
  • 34
  • 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? – trojanfoe Sep 17 '13 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? – DenverCoder21 Sep 17 '13 at 15:10
  • No, I've only used it once or twice. Google will give you a fair few hits I would imagine. – trojanfoe Sep 17 '13 at 15:14

3 Answers3

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.

David W.
  • 105,218
  • 39
  • 216
  • 337
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

Andrew Stubbs
  • 4,322
  • 3
  • 29
  • 48
0

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

czechboy
  • 899
  • 7
  • 15
  • 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. – DenverCoder21 Sep 17 '13 at 14:33
  • Oh, ok. Well, permission denied would point to the answer by Andrew Stubbs. – czechboy Sep 17 '13 at 14:36
  • 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. – DenverCoder21 Sep 17 '13 at 14:45
  • Weird. Does the script work when you just run it in Terminal with `$blabla > ./git_credentials.sh` ? – czechboy Sep 17 '13 at 14:47
  • 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. – DenverCoder21 Sep 17 '13 at 14:51
  • @DenverCoder21 "nor waits for my user inputs"... err, sorry? What does `read` do then? – trojanfoe Sep 17 '13 at 14:58
  • I'd like to know that, too. ;) When running it in a terminal, read of course waits for my user input, but when run automatically at login nothing happens, except that my Git credentials are gone except for the entry user.name = " ". So I totally makes sense that the script runs but doesn't use any user input in my mind. – DenverCoder21 Sep 17 '13 at 15:01
  • @DenverCoder21 I think you need to follow my suggestion (in a comment on your question) and use Automator for the purpose it was designed. Get the user input using Automator and call git directly and dump this shell script. – trojanfoe Sep 17 '13 at 15:02
  • On OS X scripts ran in a certain way do actually ignore user input. I suspect it to be in the case when the default input option is... not available or something. – czechboy Sep 17 '13 at 15:02