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

rebello95

macrumors member
Original poster
Jun 15, 2011
40
0
USA
I'm trying to do this shell script:

do shell script ¬
"find . -type f -name 'AmikiConnect.zip' -exec cp {} ~/Desktop/Test/File/1 \;"

but I'm getting errors about the end \;" because since there's a backslash in the bash command, it thinks there should be a " after it but there's supposed to be a ; like there is.

How can I fix this without putting it in a text file? Thanks!
 

rebello95

macrumors member
Original poster
Jun 15, 2011
40
0
USA
Yes, I already read that. The problem is when I try to run the program with double backslashes at the end, it just keeps going and doesn't stop. In the end I have to force quit the app. Any suggestions on how to fix this?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,706
8,346
A sea of green
Post the actual code that doesn't work.

And please explain what you mean by "it just keeps going and doesn't stop". If you mean "the find continues to find and copy other files", then yes, it's supposed to work that way. Did you read the man page for find to understand how it works?

If you want to search only a specific directory, then use that directory name in place of "." in the find command. Go back to your other thread and look very carefully at the "cd ~" command you were told to use before running find. Perhaps the "." you're running find from isn't the "." you think it is.

For testing you should try a simple -print action for find, look at everything it outputs, then decide what to do. If you want advice, you'll have to post that output. We can't read your mind or see your screen.
 

rebello95

macrumors member
Original poster
Jun 15, 2011
40
0
USA
Here's the code:

do shell script ¬
"find . -type f -name 'AmikiConnect.zip' -exec cp {} ~/Desktop/Test/ \\;"

Here's a screen shot showing what I mean by it keeps running... look at the bottom left of the screen shot.
RunningError.png
 

r0k

macrumors 68040
Mar 3, 2008
3,611
75
Detroit
Here's the code:

do shell script ¬
"find . -type f -name 'AmikiConnect.zip' -exec cp {} ~/Desktop/Test/ \\;"

Here's a screen shot showing what I mean by it keeps running... look at the bottom left of the screen shot.
Image

Sorry but the screenshot is blocked by our inane firewall, but when you are running a shell script, chances are . is somewhere inside the bundle or perhaps your /Applications folder. Is that what you intend? Also why do you need backslashes? Using a ; in "do shell script" allows you to string several commands together and there isn't any reason I can think of at the moment why you would need need any \.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,706
8,346
A sea of green
Also why do you need backslashes? Using a ; in "do shell script" allows you to string several commands together and there isn't any reason I can think of at the moment why you would need need any \.

The -exec action of 'find' needs an actual semicolon arg (read the find man page). One way to do that is \;. Quoting is another way, so ';' also works.


Here's the code:

do shell script ¬
"find . -type f -name 'AmikiConnect.zip' -exec cp {} ~/Desktop/Test/ \\;"

Which supports what I said about it searching the wrong directory. You left out the "cd ~", which was given to you in your other thread.

If you don't know what "." represents, i.e. you don't know the current working directory, then use a specific directory name. Blindly assuming that "." will be your home directory is madness. The find command can work on any directory you give it, as long as you have access permission. You can learn this by reading the man page for find.

If you want find to find only the first instance of the named file, I'm not sure how to do that off the top of my head. Perhaps a predicate like:
Code:
-exec killall find \;
That's just a guess. I recommend testing it to see if it works, and that it has no unexpected side effects, such as killing other 'find' processes you may want to keep running. Also, a detailed examination of the find man page may show a predicate that halts the descent.
 
Last edited:

rebello95

macrumors member
Original poster
Jun 15, 2011
40
0
USA
I tried with code

do shell script ¬
"find . -type f -name 'AmikiConnect.zip' -exec cp {} ~/Desktop/Test/ \\';'"

and got the following errors:
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
 

chown33

Moderator
Staff member
Aug 9, 2009
10,706
8,346
A sea of green
I said ';'. I didn't say \\';'.


By the way, this isn't going to affect the "it keeps running" problem at all. It's not going to affect the "working directory" problem, either.

You already had it working with \\;. It was working. It was doing exactly what it should do. The problem is that what you expected and what you actually told it to do are different. You need to understand what you're actually telling it to do.

The working directory issue has already been explained. Did you reread your other thread? Do you realize you're still not entering a 'cd ~' command?

If you don't understand an explanation, then please state that. If you don't understand how to fix it, then please state that. Blindly trying different things, none of which you understand, is not a recipe for success.
 

rebello95

macrumors member
Original poster
Jun 15, 2011
40
0
USA
Okay, sorry about that. for some reason I didn't see your post in this thread about cd ~

I ran this:

do shell script ¬
"cd ~
find . -type f -name 'AmikiConnect.zip' -exec cp {} ~/Desktop/Test/ ';'"

and it worked perfectly. Thank you so much!

So basically it was searching the whole HD, right?
 
Last edited:

r0k

macrumors 68040
Mar 3, 2008
3,611
75
Detroit
I found an example over at macscripter.net that seems to confirm the use of \\; for the find -exec command...

Code:
do shell script "/usr/bin/find /Volumes/TS-Leenbakker/JPEG/10/101/ -name '*_Landscape*' -type f -exec cp {} '/Path/to/destination/folder' \\;"

Also the web page suggested by chown33 requires less than half an hour reading and explains the whole backslash issue quite well.

Can you explain more about why you don't appear to care about the path? Is it that you know that . is inside the bundle and the files you are looking for are inside the bundle? It could be that running the script inside the script editor moves . somewhere else and . turns out to be inside the applescript editor's bundle. I have heard there is a way to run your script "as an app" and force it to run outside the script editor environment and have its own path, bundle, etc. Perhaps that is what you need to do.

Oops. Nevermind. I was typing slowly while you were typing...
Okay, sorry about that. for some reason I didn't see your post in this thread about cd ~

I ran this:

do shell script ¬
"cd ~
find . -type f -name 'AmikiConnect.zip' -exec cp {} ~/Desktop/Test/ ';'"

and it worked perfectly. Thank you so much!

So basically it was searching the whole HD, right?

No it was probably searching inside applescript editor's bundle.

So thanks again and sorry for my non-understanding a few times there ;)

Nothing to be sorry about. It's not a crime to ask a question. It's sometimes a crime NOT to ask a question like "Are the seawalls near my reactor high enough?"
 

rebello95

macrumors member
Original poster
Jun 15, 2011
40
0
USA
The reason I don't care about adding a path is because I don't know the exact path. The files I'm looking for are in the bundle. The bundle will be downloaded originally as a .zip then extracted to wherever the user wants. Because I don't know that they'll put it in a definite directory, I'm having it simply find the file.

And I have the script saved as a read/run-only application that runs on its own (it is a .app), and the files I'm looking for are in the bundle, like I said before.

----------

Lol :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.