• 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: "L. Lee" <email@hidden>
  • Date: Wed, 25 Apr 2012 14:34:31 -0500
  • Thread-topic: Unknown token in do shell script

Title: Re: Unknown token in do shell script
Here's my two cents. It has a lot of stuff, and I'm not finished testing, because I want to see what it will do with a disk that has a different name in the sidebar or on the desktop from that which is displayed for it in "/Volumes".

property infoitemlist : {"name"}

set dur to {}
list disks
repeat with m in result
    considering case
        if m is not in {"MobileBackups", "home", "net"} then
            set dur to dur & m
        end if
    end considering
end repeat

set theobjects to dur
set im to {}
repeat with theobject in theobjects
    set m to realinfo(theobject)
    set im to im & m
end repeat

set devnames to paragraphs of (do shell script "df -k | awk -F/ '/disk*/ {print $3}'")

set t to {}
repeat with s in devnames
    set t to t & (word 1 of s)
    --delay 1
end repeat

set the keylist to im
set the foundDisks to t

set answer_list to {}

repeat with the_answer in keylist
    set theIndex to my CollectUniqueItemIndex(keylist, (the_answer as string))
    set theValue to item theIndex of foundDisks
    activate
    --set answer_list to answer_list & return & ((the_answer & ":" & space & theValue) as string)
    --set answer_list to answer_list & ((the_answer & ":" & space & theValue) as string)
    set answer_list to answer_list & (the_answer as string)
end repeat
--answer_list as string


set your_selected_device_id to choose from list answer_list with prompt "Please choose a volume to be unmounted."

set theIndex to my CollectUniqueItemIndex(answer_list, (your_selected_device_id as string))
set theValue to item theIndex of foundDisks
display dialog "The device name of the volume you selected is:" & space & "\"" & theValue & "\"." & space & "Are you sure you want to unmount it?"

do shell script "diskutil unmount /dev/" & theValue

on CollectUniqueItemIndex(theList, theItem) -- the Item can be string, number, constant, app object or list    
    local aListMember
    repeat with i from 1 to (count theList)
        set aListMember to item i of theList
        if aListMember = theItem then
            set theIndex to i
            exit repeat
        end if
    end repeat
    return theIndex
end CollectUniqueItemIndex

on realinfo(theobject)
    tell application "Finder"
        set theRealInfo to get (properties of disk theobject)
    end tell
    set coll to ""
    repeat with i in infoitemlist
        set namelabel to i as Unicode text
        --set coll to coll & return & namelabel & ":" & space & (extract_usrf(theRealInfo, namelabel) as text)
        set ren to (extract_usrf(theRealInfo, namelabel) as text)
    end repeat
    --return ren
end realinfo

to extract_usrf(theRecord, fieldName)
    script Ford
        property r : theRecord
        to extract() -- supply a dummy method
        end extract
    end script
    set Arthur to run script "script Zaphod
        property r : {}
         to extract()
         return " & fieldName & " of r
         end extract
     end
     Zaphod"
    set Ford's extract to Arthur's extract
    return (Ford's extract())
end extract_usrf


--
Laine Lee

On 3/9/12 9:01 AM, "Axel Luttgens" <email@hidden> wrote:

> 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: > email@hidden Archives:
> http://lists.apple.com/archives/applescript-users This email sent to
> email@hidden
 _______________________________________________
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

  • Prev by Date: Re: Safari Tab Pick-List
  • Next by Date: Re: Safari Tab Pick-List
  • Previous by thread: Re: Am I missing something here? I thought there was an elegant way to do this.
  • Next by thread: Mailboxes in Mail & Applescript
  • Index(es):
    • Date
    • Thread