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 > Mac OS X > Problems properly escaping an osascript alias

Problems properly escaping an osascript alias
Thread Tools
Senior User
Join Date: Apr 2000
Location: Woodridge, IL
Status: Offline
Reply With Quote
Oct 7, 2003, 09:18 PM
 
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
Reply With Quote
Oct 7, 2003, 10:05 PM
 
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
Reply With Quote
Oct 8, 2003, 09:36 AM
 
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
Reply With Quote
Oct 9, 2003, 02:26 AM
 
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
Reply With Quote
Oct 9, 2003, 10:22 AM
 
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
Reply With Quote
Oct 10, 2003, 02:00 AM
 
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
Reply With Quote
Oct 10, 2003, 09:48 AM
 
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
Reply With Quote
Oct 11, 2003, 05:27 PM
 
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
Reply With Quote
Oct 13, 2003, 09:22 AM
 
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.
     
   
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 08:36 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