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

sitryd

macrumors member
Original poster
Sep 19, 2006
31
1
Hey all,

I'm assuming this is a simple question, but I can't find any good documentation online on it.... I'm trying to write an applescript to automatically back up a copy of my notes for classes to a flash drive whenever its plugged in. The problem is that the directory path for the source file has a space in it, and Applescript is bouncing back an error "Expected “"” but found unknown token."

Here's the relevant portion of the script:

ignoring application responses
tell application "Terminal"
activate
do shell script "rsync -a /Users/Sitryd/Documents/07-08 2L/\ Constitutional\ Law/Constitutional\ Law\ Notes.doc /Volumes/Backups/"
end tell
end ignoring

It's hiccuping right after the \ in the "07-08 2L/\" sequence (i.e. at the first space), but I can't figure out how to have applescript just pass that sequence normally to terminal.

Thanks!
 

MongoTheGeek

macrumors 68040
Hey all,

I'm assuming this is a simple question, but I can't find any good documentation online on it.... I'm trying to write an applescript to automatically back up a copy of my notes for classes to a flash drive whenever its plugged in. The problem is that the directory path for the source file has a space in it, and Applescript is bouncing back an error "Expected “"” but found unknown token."

Here's the relevant portion of the script:

ignoring application responses
tell application "Terminal"
activate
do shell script "rsync -a /Users/Sitryd/Documents/07-08 2L/\ Constitutional\ Law/Constitutional\ Law\ Notes.doc /Volumes/Backups/"
end tell
end ignoring

It's hiccuping right after the \ in the "07-08 2L/\" sequence (i.e. at the first space), but I can't figure out how to have applescript just pass that sequence normally to terminal.

Thanks!
anytime you want to put quotes inside an applescript string you have to put a backslash (\") first. If you want to put an actual backslash in the string you have to put a backslash in front of it. (\\)

other useful ones

\r --> return
\t --> tab
\n --> newline
 

sitryd

macrumors member
Original poster
Sep 19, 2006
31
1
Hmm think i wasnt very clear with my question. I dont actually want to have the \ or a quote in the script. From what I've read the " marks are necessary for the rsync command (i.e. send "rsyc -a /Source /Destination" to the terminal).

The actual source is /Users/Sitryd/Documents/07-08 2L/Constitutional Law/Constitutional Law Notes.doc . To tell the terminal to preserve the spaces in the sourcepath, I had to put the "\"s in, leaving /Users/Sitryd/Documents/07-08 2L/\ Constitutional\ Law/Constitutional\ Law\ Notes.doc /Volumes/Backups/.

This leaves the script as:

ignoring application responses
tell application "Terminal"
activate
do script "rsync -a /Users/Sitryd/Documents/07-08\ 2L/\ Constitutional\ Law/Constitutional\ Law\ Notes.doc /Volumes/Backups/"
end tell
end ignoring


Yet rather than treating the portion within the quotation marks as a single command to send to the terminal, applescript is hitting the first space and giving an error. I seem to need the quotes, since without them it comes back with an "expected end of line" error.

Thanks in advance!
 

MongoTheGeek

macrumors 68040
The actual source is /Users/Sitryd/Documents/07-08 2L/Constitutional Law/Constitutional Law Notes.doc . To tell the terminal to preserve the spaces in the sourcepath, I had to put the "\"s in, leaving /Users/Sitryd/Documents/07-08 2L/\ Constitutional\ Law/Constitutional\ Law\ Notes.doc /Volumes/Backups/.

Yet rather than treating the portion within the quotation marks as a single command to send to the terminal, applescript is hitting the first space and giving an error. I seem to need the quotes, since without them it comes back with an "expected end of line" error.

Thanks in advance!

Like having to put the \ in front of the space to get terminal to preserve the space in the file name you have to put a \ in front of the \ to make Applescript realize that you want to have a \ in the string that the shell needs to see the file.

what you need is
Code:
ignoring application responses
    tell application "Terminal"
        activate
        do script "rsync -a /Users/Sitryd/Documents/07-08\\ 2L/\\ Constitutional\\ Law/Constitutional\\ Law\\ Notes.doc /Volumes/Backups/"
    end tell
end ignoring

or

Code:
ignoring application responses
    tell application "Terminal"
        activate
        do script "rsync -a \"/Users/Sitryd/Documents/07-08 2L/ Constitutional Law/Constitutional Law Notes.doc\" /Volumes/Backups/"
    end tell
end ignoring

or perhaps most simply

Code:
ignoring application responses
    tell application "Terminal"
        activate
        do script "rsync -a '/Users/Sitryd/Documents/07-08 2L/ Constitutional Law/Constitutional Law Notes.doc' /Volumes/Backups/"
    end tell
end ignoring

You should also look into do shell script in the standard additions.
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
..

ignoring application responses
tell application "Terminal"
activate
do script "rsync -a /Users/Sitryd/Documents/07-08\ 2L/\ Constitutional\ Law/Constitutional\ Law\ Notes.doc /Volumes/Backups/"
end tell
end ignoring

...

Shouldn't that be "do shell script ...". The rest looks fine. Your original post looked like it didn't have the "\ " between 08 and 2L, which would have been giving you issues. I'd try this out, but I don't have those specific folders of course.
 

pepeleuepe

macrumors 6502
Oct 27, 2002
252
0
Los Angeles, California
I just setup rsync last night and had a similar problem. I ended up using the "quoted form of" command in applescript to solve my specific problem. I think it might work for you as well.

Check out this little tutorial: http://www.oreillynet.com/pub/a/mac/2005/07/22/backup.html?page=2

or give this a shot:

Code:
do shell script "rsync -a " & quoted form of "/Users/Sitryd/Documents/07-08 2L/ Constitutional Law/Constitutional Law Notes.doc" & " /Volumes/Backups/"
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.