Hi there
I am trying to do a short applescript to execute a shell script.
In terminal, I type “disktool -l | egrep -i “Mountpoint = ‘’, fsType = ‘hfs’, volName = '.*Temp” | cut -d' -f2 | xargs -n1 disktool -m” (minus the start and end quote marks). This works well and mounts disk as expected.
When I patch and paste into Script Editor as follows:
do shell script “disktool -l | egrep -i “Mountpoint = ‘’, fsType = ‘hfs’, volName = '.*Temp” | cut -d' -f2 | xargs -n1 disktool -m”
… it refuses to compile giving a Syntax Error [A identifier can’t go after this “”“], and highlights the word “Mountpoint” (including the preceding quote mark”
I am obviously having problems with single/double quotation marks in the wrong place but I have been unable to resolve this.
Can anyone help?
From man disktool:
"This command is deprecated and exists only for backwards compatibility.
Do not use disktool, use diskutil instead."
Can you get the command to work from the Terminal?
You have to escape some characters.
-- \"Mountpoint
-- -d\\'
do shell script "disktool -l | egrep -i \"Mountpoint = '', fsType = 'hfs', volName = '.*Temp\" | cut -d\\' -f2 | xargs -n1 disktool -m"
Wow. Thanks. Quick and it works! Not sure I am going to fiddle with diskutil as disktools seems to just work for the time being…
Just so you understand this one, AppleScript uses the quote symbol to determine what part of your statement is the shell command.
Therefore, when you say:
do shell script “disktool -l | egrep -i “Mountpoint = ‘’, fsType = ‘hfs’, volName = '.*Temp” | cut -d' -f2 | xargs -n1 disktool -m”
AppleScript breaks this down into:
do shell script “disktool -l | egrep -i "
Mountpoint = ‘’, fsType = ‘hfs’, volName = '.*Temp” | cut -d' -f2 | xargs -n1 disktool -m
As you can see, the shell script contains only the ‘disktool -l | egrep -i’ part and the ‘Mountpoint’ is interpreted as a new statement.
The basic fix for this is to escape the quote characters with a leading backslash - this tells AppleScript not to use it as a delimiter, but to include it in the string itself. In other words " tells AppleScript to include the quote symbol in the text rather than treating this as the end of the string (which it would normally do).
Thanks for the solution and, Camelot, for the explanation. Much appreciated.