Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

quarkrad

macrumors member
Original poster
Jun 29, 2009
41
1
Written a rsync script to sync two local folders via the Automator. This is a test to see if it all works - I have two permanently connected drives I want to sync. Everything is working fine - I have an icon in the Dock I can click on that, in effect, runs the rsync script. I have a similar set up in a Linux environment that is similar except a terminal in present on the Desktop whilst the script is running so you can see what is happening/when it has finished. Having got the script running/working on OSX is it possible (how) to have a terminal running on the Desktop showing the sync'ing? Thank you.
 

Stephen.R

Suspended
Nov 2, 2018
4,356
4,747
Thailand
Rather than using the Automator part, put the rsync command into a text file with the extension .command (ie sync.command), with the following on the first line (above the Rsync command)


Bash:
#!/bin/sh

<your rsync command here>
[automerge]1593288564[/automerge]
Oh sorry forgot to add - you should be able to then double click (or open from the dock) the .command file and it will run, showing the terminal, and then close the window when it completes
 

quarkrad

macrumors member
Original poster
Jun 29, 2009
41
1
Still got trouble. The script is called rsync.command and looks like this:

#! /bin/zsh
rsync -a /Users/dad/Documents /Users/dad/Downloads


I have made the script executable. When I double click on it I get this:

Last login: Sun Jun 28 07:18:19 on ttys000
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
/Users/dad/Desktop/rsync.command ; exit;
dads-iMac:~ dad$ /Users/dad/Desktop/rsync.command ; exit;
/Users/dad/Desktop/rsync.command: line 1: {rtf1ansiansicpg1252cocoartf2513: command not found
/Users/dad/Desktop/rsync.command: line 2: syntax error near unexpected token `}'
/Users/dad/Desktop/rsync.command: line 2: `\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;}
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.


I'm not sure where to go from here.
[automerge]1593350095[/automerge]
Nearly forgot:


dads-iMac:~ dad$ echo $SHELL
/bin/zsh
dads-iMac:~ dad$
 

Taz Mangus

macrumors 604
Mar 10, 2011
7,815
3,504
Make sure
Still got trouble. The script is called rsync.command and looks like this:

#! /bin/zsh
rsync -a /Users/dad/Documents /Users/dad/Downloads


I have made the script executable. When I double click on it I get this:

Last login: Sun Jun 28 07:18:19 on ttys000
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
/Users/dad/Desktop/rsync.command ; exit;
dads-iMac:~ dad$ /Users/dad/Desktop/rsync.command ; exit;
/Users/dad/Desktop/rsync.command: line 1: {rtf1ansiansicpg1252cocoartf2513: command not found
/Users/dad/Desktop/rsync.command: line 2: syntax error near unexpected token `}'
/Users/dad/Desktop/rsync.command: line 2: `\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;}
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.


I'm not sure where to go from here.
[automerge]1593350095[/automerge]
Nearly forgot:


dads-iMac:~ dad$ echo $SHELL
/bin/zsh
dads-iMac:~ dad$

I think I see the issue. Change:
Code:
#! /bin/zsh
To:
Code:
#!/bin/zsh
 

Taz Mangus

macrumors 604
Mar 10, 2011
7,815
3,504
A space won't actually stop it working (I wasn't sure but I just tried it)

Then it appears to me that what it looks like is it is using the output from the rsync command, as if that is the commands to execute.
[automerge]1593361529[/automerge]
What editor was used to create the rsync.command file.
 
Last edited:

bernuli

macrumors 6502a
Oct 10, 2011
713
404
your rsync.command file needs to be a text file. I think what you have is an RTF file
 

quarkrad

macrumors member
Original poster
Jun 29, 2009
41
1
Thank you all. You were right - it was an RTF file - opened and reformated to plane text but still no luck. I have taken some pictures that might help.
 

Attachments

  • a.png
    a.png
    194.7 KB · Views: 146
  • b.png
    b.png
    292.5 KB · Views: 180
  • c.png
    c.png
    270.3 KB · Views: 151

NoBoMac

Moderator
Staff member
Jul 1, 2014
6,286
4,974
I do this with some scripts I have. Pretty easy to change the Automator script.

Code:
on run {input, parameters}
    
    tell application "Terminal"
        do script "/Users/yourusername/Applications/yourscripthere '" & someparam & "'"
        activate   -- this brings the Terminal window up
    end tell
    
    
    return input
end run
 

Taz Mangus

macrumors 604
Mar 10, 2011
7,815
3,504
Thank you all. You were right - it was an RTF file - opened and reformated to plane text but still no luck. I have taken some pictures that might help.

For some reason the OS is forcing the use of bash. If you look at the title on the Terminal window it says bash not zsh. Try doing what it suggests:
Code:
chsh -s /bin/zsh

EDIT: Or the easiest solution, just change the top line in the script to:
Code:
#!/bin/bash
 
Last edited:
  • Like
Reactions: bernuli

quarkrad

macrumors member
Original poster
Jun 29, 2009
41
1
When I run the script as is nothing happens
If I change from /bin/zsh to bin/bash nothing happens (also tried changing from rsync.command to rsync.sh)
The automator works so .... is this the amended script?

on run {input, parameters}

tell application "Terminal"
do script "/Users/dad/Applications/rsync -a /Users/dad/Documents /Users/dad/Downloads '" & someparam & "'"
activate -- this brings the Terminal window up
end tell


return input
end run
[automerge]1593375525[/automerge]
When I say nothing happens - I get this output
(note: I changed the name of the script to com.command)
 

Attachments

  • e.png
    e.png
    37.4 KB · Views: 174

quarkrad

macrumors member
Original poster
Jun 29, 2009
41
1
Finally - thank you for you help.

Created plan text document
Made executable chmod a+x
Dragged into doc
Doc called xx.command

notes: I also wanted progress window (terminal) to pop up showing me progress of transfer

Contents of file:

#! /bin/zsh
rsync -av -P /Users/dad/Documents/ /Users/dad/Downloads
 

Taz Mangus

macrumors 604
Mar 10, 2011
7,815
3,504
Finally - thank you for you help.

Created plan text document
Made executable chmod a+x
Dragged into doc
Doc called xx.command

notes: I also wanted progress window (terminal) to pop up showing me progress of transfer

Contents of file:

#! /bin/zsh
rsync -av -P /Users/dad/Documents/ /Users/dad/Downloads

So the issue had to do with the format of the text file?
 

quarkrad

macrumors member
Original poster
Jun 29, 2009
41
1
Yes - that was fundamental. I originally used the built-in text edit tool to create the original file and it saved itself as a RTF file. Once I re-formatted it to plane text all was fine.
 

jasnw

macrumors 65816
Nov 15, 2013
1,032
1,134
Seattle Area (NOT! Microsoft)
If you're going to be doing much of this sort of thing in the future (making scripts for the OS to run in a shell) you might want to download the free version of BBedit. It's pretty easy to use, and is geared towards working with text-format files. (If you really want to get down to "bare bones" you might try running the vi editor or, if you are really masochistic, emacs from the command line in Terminal. That's where I live mostly, but vi and emacs are not for people who just have an occasional need to fiddle with shell scripts.)
 
  • Like
Reactions: bernuli
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.