1

I want to update my git Bitbucket online storage with apple script. This is the code that works in Terminal, but not when i run apple script.

cd /Users/mainuser/Desktop/Projects git add -A
git commit -m fromAppleScript
git push

crafted into apple script:

        say "updating backup"
        do shell script "cd /Users/mainuser/Desktop/Projects git add -A"
        do shell script "cd /Users/mainuser/Desktop/Projects git commit -m fromAppleScript"
        do shell script "cd /Users/mainuser/Desktop/Projects git push"

I am a bit puzzled why this code doesn't work. Can you help me out with this problem?

4
  • Do you have a shell script or commands that work when issued from within Terminal.app? Do you need help changing directory into your project and running git push? Commented Apr 27, 2016 at 12:13
  • I dont know how to do it, not even in Terminal.
    – sanjihan
    Commented Apr 27, 2016 at 12:24
  • 2
    git can be tricky to learn and debug. Consider mastering the steps you want via Terminal.app – with the help of the Git Book. BitBucket support provides a wealth of examples and workflows to try and to learn from. Once you trust that process, automating via AppleScript will be much easier. Commented Apr 27, 2016 at 13:11
  • 1
    You may need to separate the cd command from the git command in each line with a semi-colon: "cd ...; git ..."
    – mtklr
    Commented Apr 27, 2016 at 13:41

1 Answer 1

3

You appear to be using git as a file system back-up. Have you considered git-annex?

Learning git

git can be tricky to learn and debug. Consider mastering the steps you want via Terminal.app – with the help of the Git Book.

BitBucket support provides a wealth of examples and workflows to try and to learn from. Once you trust that process, automating via AppleScript will be much easier.

Fixing the Shell Script

To get you started, there are is a problem with the AppleScript. The script passed to do shell script will return an error:

do shell script "cd /Users/mainuser/Desktop/Projects git add -A"

Within these quotes you are issuing two commands: one to change directory, and the second to add files to git. These two commands need to be separated with a semi-colon:

do shell script "cd /Users/mainuser/Desktop/Projects; git add -A"

A better approach still, would be to tie the commands together with &&. This will mean that if the first command fails, the second command is not performed. This approach deals with the problem of a missing or renamed directory:

do shell script "cd /Users/mainuser/Desktop/Projects && git add -A"

Alternatively, to avoid working directory concerns try passing the full path to the git commands:

do shell script "git add -A '/Users/mainuser/Desktop/Projects'"

You must log in to answer this question.

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