 |
 |
Problems properly escaping an osascript alias
|
 |
|
 |
|
Senior User
Join Date: Apr 2000
Location: Woodridge, IL
Status:
Offline
|
|
Hello, everyone. I'm trying to add an alias to my tcshrc file to run a simple script. The script is simply:
tell application "Finder" to set visible of every process whose visible is true and name is not "Finder" to false
Which in effect hides everything except the Finder. My problem is that no matter how I escape characters, use double and single quotes, or split the lines, I can't seem to come up with an alias that gets by the interpreter. Here is the line I've been working with:
alias hide 'osascript -e "tell application \"Finder\" to set visible of every process whose visible is true and name is not \"Finder\" to false"'
Does anyone know what I'm doing wrong here? 
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status:
Offline
|
|
Probably easier to put the applescript in its own file saved as a .scrpt (or whatever the extension is) in ~/bin and then call that with your alias.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Apr 2000
Location: Woodridge, IL
Status:
Offline
|
|
Originally posted by clarkgoble:
Probably easier to put the applescript in its own file saved as a .scrpt (or whatever the extension is) in ~/bin and then call that with your alias.
I can do that, of course, but it really shouldn't be necessary for a one-line AppleScript. I'd much rather know that by just copying over my tcshrc that I have everything.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status:
Offline
|
|
Originally posted by diamondsw:
alias hide 'osascript -e "tell application \"Finder\" to set visible of every process whose visible is true and name is not \"Finder\" to false"'
Does anyone know what I'm doing wrong here?
Hmmm... works just fine in bash (assuming you add an "=" after "hide", that is, as per bash alias syntax). Your quoting seems to be correct. Have no idea why it's not working for you.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Apr 2000
Location: Woodridge, IL
Status:
Offline
|
|
Originally posted by Rainy Day:
Hmmm... works just fine in bash (assuming you add an "=" after "hide", that is, as per bash alias syntax). Your quoting seems to be correct. Have no idea why it's not working for you.
Interesting - so it's limited to some funkiness in the tcsh... Man, that could be ugly. I'll look up some tcsh references.
Thanks!
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2001
Status:
Offline
|
|
I think it's indeed the way you quote the quotes. Try:
alias hide 'osascript -e "tell application "\""Finder"\"" to set visible of every process whose visible is true and name is not "\""Finder"\"" to false"'
Read "\"" as:
" - leave the doublequote modus
\" - insert a double quote
" - enter the doublequote modus again
-
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Apr 2000
Location: Woodridge, IL
Status:
Offline
|
|
Originally posted by Moonray:
I think it's indeed the way you quote the quotes. Try:
alias hide 'osascript -e "tell application "\""Finder"\"" to set visible of every process whose visible is true and name is not "\""Finder"\"" to false"'
Read "\"" as:
" - leave the doublequote modus
\" - insert a double quote
" - enter the doublequote modus again
-
Wouldn't that screw up the osascript command? I'll try it later when I have the chance. In the meantime, I found an ugly solution (and this is all due to tcsh not handling nested quotes well at all  ):
set DQ = '"'
alias hide 'osascript -e "tell application ${DQ}Finder${DQ}" -e "activate" -e "set visible of every process whose visible is true and name is not ${DQ}Finder${DQ} to false" -e "end tell"'
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2001
Status:
Offline
|
|
Originally posted by diamondsw:
Wouldn't that screw up the osascript command? I'll try it later when I have the chance.
The -e parameter expects "one word" as script. You can put one word together in tcsh if you quote at least all parts that contain spaces (or" "only" "the" "spaces).
In the meantime, I found an ugly solution (and this is all due to tcsh not handling nested quotes well at all ):
Nested quotes are handled fine, just quoting quotes within quotes with a backslash does not work. So you have to end quote mode before you insert a quoted quote and start quote mode again  but this is by design. There's a shell variable you can set to get \" working within quotes.
set DQ = '"'
alias hide 'osascript -e "tell application ${DQ}Finder${DQ}" -e "activate" -e "set visible of every process whose visible is true and name is not ${DQ}Finder${DQ} to false" -e "end tell"'
Looks a bit ... ehh ... weird
-
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Apr 2000
Location: Woodridge, IL
Status:
Offline
|
|
Originally posted by Moonray:
The -e parameter expects "one word" as script. You can put one word together in tcsh if you quote at least all parts that contain spaces (or" "only" "the" "spaces).
Nested quotes are handled fine, just quoting quotes within quotes with a backslash does not work. So you have to end quote mode before you insert a quoted quote and start quote mode again but this is by design. There's a shell variable you can set to get \" working within quotes.
-
Thanks a lot! You learn something new every day in the UNIX forum.
Looks a bit ... ehh ... weird
That it does, that it does. 
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|