Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > AppleScript & do shell script woes...

AppleScript & do shell script woes...
Thread Tools
Fresh-Faced Recruit
Join Date: Apr 2000
Status: Offline
Reply With Quote
Sep 1, 2002, 08:24 AM
 
Hey all,

Just wondering if someone can throw out some feedback as to what's snagging me up here. I've just started using (or at least I'm trying to use it) the "do shell script" command and I'm having problems getting it to work correctly.

Let's say I want a script that will mount a certain disc image without actually launching Toast or Disc Copy. In the terminal, this is what I'd type:

% /Applications/Roxio\ Toast\ Titanium\ 5.1.4/Toast\ Titanium\ 5.1.4.app/Contents/MacOS/ToastImageMounter\

Followed by:

-> /Users/me/Desktop/My\ CD.toast

So what would be the correct AppleScript syntax to get something like this to work? Any input would be greatly appreciated.

Thanks,

Troy
     
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Sep 1, 2002, 11:43 AM
 
Try something like this:

"/folder/the file"

Meaning, just add `"' on both sides. This works. Not always though.

This works:
cp "./a file" ~/Desktop/

While this doesn't:
cp "./a file" "~/Desktop/another file"
     
troyw  (op)
Fresh-Faced Recruit
Join Date: Apr 2000
Status: Offline
Reply With Quote
Sep 1, 2002, 05:52 PM
 
Thanks, Vegan. I have tried that and get a zsh execution error. It says there's no such file or directory, and refers to "Applications/Roxio" (I think it's getting hung up on the space in the pathname).
     
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Sep 1, 2002, 06:24 PM
 
Could you show us the actually AppleScript code you are trying to run? It sounds like you aren't quoting the path names correctly.
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
troyw  (op)
Fresh-Faced Recruit
Join Date: Apr 2000
Status: Offline
Reply With Quote
Sep 1, 2002, 07:55 PM
 
As soon as I'm back on that OS X machine I'll post the code. I've tried so many different variations I'm now thoroughly confused and don't want to further complicate matters by relying on my rather feeble memory...

One thing's for sure: I think I'm missing something very fundamental about the do shell script command and how it should be written.

Using my previous terminal example, how should the AppleScript syntax look (both in terms of the path, as well as binding the two commands together)?

Thanks for y'all's continued input!
     
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Sep 1, 2002, 08:34 PM
 
do shell script "\"/Applications/Roxio Toast Titanium 5.1.4/Toast Titanium 5.1.4.app/Contents/MacOS/ToastImageMounter\" \"/Users/me/Desktop/My CD.toast\""

Would be code for running that shell command. Notice the \" strings, in bold. You need those to escape the quotes around your command name and your parameter. Probably the problem you were having was trying to escape the spaces with "\ ", because that escape sequence will not be passes to the shell, it will be interpreted by applescript. If you wanted to use them instead of quoting, you could do it i think, but you would need to escape the shell escape mark, so it would be like this "\\ ". That way, AppleScript will interpret the \\ as \, and so the shell will actually see "\ ". Hope that didn't come out to convoluted sounding Good luck.
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Sep 2, 2002, 01:01 AM
 
Originally posted by Mactoid:
do shell script "\"/Applications/Roxio Toast Titanium 5.1.4/Toast Titanium 5.1.4.app/Contents/MacOS/ToastImageMounter\" \"/Users/me/Desktop/My CD.toast\""
I clearly told you that the destination MAY NOT BE QUOTED!!!

do shell script ("\"/Applications/Roxio Toast Titanium 5.1.4/Toast Titanium 5.1.4.app/Contents/MacOS/ToastImageMounter\"
~/Desktop/My\\ CD.toast")
     
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Sep 2, 2002, 12:10 PM
 
Originally posted by VEGAN:
I clearly told you that the destination MAY NOT BE QUOTED!!!
Hold up there! Where did you tell me this, and more importantly why? I have never heard of any such thing. What is wrong with quoting the destination?
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
troyw  (op)
Fresh-Faced Recruit
Join Date: Apr 2000
Status: Offline
Reply With Quote
Sep 2, 2002, 03:02 PM
 
Thank you both for the examples. Mactoid, your explanation was especially helpful. My problem was stemming from having quotes and backslashes in the wrong place.

I'm seeing one additional problem though (true with both code samples)...

When I run the script, it mounts the image just as it should, but never reaches a conclusion. Script Editor just hangs until I unmount the disc manually from the desktop. On the other hand, if I nest this particular do shell script command inside of an if-then-else statement, the disc never mounts and the Finder locks up. When I relaunch the Finder, the disc is there as it should be.

I've never seen this sort of behavior with other instances of the do shell script command. Is there perhaps something missing in the line of code that might fix this?

Thanks again!
(Last edited by troyw; Sep 2, 2002 at 03:18 PM. )
     
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Sep 2, 2002, 03:22 PM
 
Oh yeah, I think I know the problem. Try appending " > /dev/null 2>&1" to your shell command. If stdout and stderr aren't redirected, then The shell command doesn't return immediately. I think that's the problem you're having.
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Sep 2, 2002, 03:32 PM
 
Originally posted by Mactoid:
Hold up there! Where did you tell me this, and more importantly why? I have never heard of any such thing. What is wrong with quoting the destination?
Er... I must have told it to you... because I stated so earlier before your post...

And the fact is that within AppleScript, at least, it doesn't like it at all if you do shell script and use `"' marks around the destination. I have always got errors with it.
     
troyw  (op)
Fresh-Faced Recruit
Join Date: Apr 2000
Status: Offline
Reply With Quote
Sep 2, 2002, 04:20 PM
 
Thanks, Mactoid -- you pegged it! Everything works perfectly now.

FYI, both code snippets seem to work great. Odd that you've always seen errors with the destination quoted, Vegan. Most of the samples I've found on the Web suggest doing that. Oh well, I guess whatever works...

Best to both of you! I appreciate the assist.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:43 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2