0

I am running a Mac using OSX Yosemite v10.10.5.

I want to push my local git repo to my remote using AppleScript.

So the git code would be:

shell
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/myusername/my-project.git
git push -u origin master

But in order to run this from the terminal, first I need to cd into my local directory.

cd my-directory

So how would I do all this from an AppleScript? Or the JavaScript option in the Script Editor would also help.

6
  • Why AppleScript and not just a simple shell script?
    – nohillside
    Apr 16, 2016 at 8:09
  • @patrix: Because I will be automating it using Automator. And from what I know, Automator can only run AppleScript (and maybe JavaScript too). But not shell script. But, I will take answers about shell script too. If anyone has one. It's possible I could figure out the AppleScript from the Shell script as a starting point.
    – Mowzer
    Apr 16, 2016 at 8:10
  • Even with Automator it might be easier to just include a "Run shell script" action and run the lines from above (including the cd) from there.
    – nohillside
    Apr 16, 2016 at 8:11
  • @patrix: Yes, I just tried that approach. And got an error in the line after the cd command. So I don't think the cd works from shell? Maybe shell has a different means of accessing the command space inside the directory?
    – Mowzer
    Apr 16, 2016 at 8:14
  • Most probably the working directory of your Automator action is not what you expect it to be. Try cd /full/path/to/my-directory instead. If it doesn't help, please ask a new question showing both the relevant part of the Automator action and the error you are getting
    – nohillside
    Apr 16, 2016 at 8:16

1 Answer 1

1

Basically you can use

do shell script "cd my-directory && git init"
do shell script "cd my-directory && git add README.md"
...
1
  • Oooohhhhh. Yeah. I didn't think of the &&. I was doing it as a separate line. Let me try that approach. Thanks.
    – Mowzer
    Apr 16, 2016 at 8:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .