• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unknown token in do shell script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unknown token in do shell script


  • Subject: Re: Unknown token in do shell script
  • From: Axel Luttgens <email@hidden>
  • Date: Fri, 09 Mar 2012 16:01:16 +0100

Le 8 mars 2012 à 19:23, Iurista GmbH a écrit :

> [...]
>
> Hi
>
> I want to unmount a volume.
> When I enter in Terminal  % diskutil unmount /Volumes/myDisk\ Leo, that works fine.
> Now I write an applescript: do shell script "diskutil unmount /Volumes/myDisk Leo", that does not work
> But if I write:             do shell script "diskutil unmount /Volumes/myDisk\ Leo",  Applescript says that the backslash is an unknown token...
>
> What do I wrong?

Hello Rudolf,

In your string "diskutil unmount /Volumes/myDisk\ Leo", the backslash is interpreted by AppleScript, and used as an escape character.

Unlike what happens with other programming languages, the backslash is very specialized, and just allows to escape a double-quote and a backslash; any other character following a backslash raises that syntax error related to an "unknown token".

So, since you want AppleScript to pass a backslash to the shell (the one coming before the space), you have to escape it in your AppleScript string:

	do shell script "diskutil unmount /Volumes/myDisk\\ Leo"

Now, as others already suggested, this one is far more easier (as well as safer):

	do shell script "diskutil unmount " & quoted form of "/Volumes/myDisk Leo"


HTH,
Axel


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden


References: 
 >Unknown token in do shell script (From: Iurista GmbH <email@hidden>)

  • Prev by Date: Re: Unknown token in do shell script
  • Next by Date: AUTO: Allyn Martin is out of office.
  • Previous by thread: Re: Unknown token in do shell script
  • Next by thread: Re: Unknown token in do shell script
  • Index(es):
    • Date
    • Thread