Re: using a shell variable in an osascript line?
Re: using a shell variable in an osascript line?
- Subject: Re: using a shell variable in an osascript line?
- From: "Mark J. Reed" <email@hidden>
- Date: Fri, 27 Feb 2009 10:41:42 -0500
On Fri, Feb 27, 2009 at 10:35 AM, René v Amerongen <email@hidden> wrote:
> How do I get the result 'button returned:OK' back or the Cancelled value?
>
> $VAR2= osascript -e 'tell application "Finder"' -e "activate" -e "display
> dialog \"$(echo "$VAR1" | sed -e 's/"/\\"/g')\"" -e 'end tell'
You don't use $ on the left hand side of shell assignments. Unlike
Perl, the $ is not part of the variable name, but a sort of "expand
this" operator.
And VAR2= command just sets VAR2 to nothing for the duration of the
command. What you want is to capture the output of the command, which
you do with command substitution, either traditional `...` or modern
$(...).
VAR2="$(osascript ...)"
But I'm not sure what osascript will actually output in this case.
You might want to stick a "button returned of result" on the end of
the Applescript.
> doen't work.
>
> On 27 feb 2009, at 16:08, Mark J. Reed wrote:
>
>> On Fri, Feb 27, 2009 at 9:45 AM, Mark J. Reed <email@hidden> wrote:
>>>
>>> Assuming your shell is bash, this will work:
>>>
>>> osascript -e "display dialog \"$(printf %q "$VAR1")\""
>>
>> I take that back. That won't work, because printf %q backslash-escapes
>> characters other than double quotes (including apostrophes and
>> spaces), causing Applescript to reject the string as invalid.
>>
>> So I guess we're back to escaping any quotes manually:
>>
>> osascript -e "display dialog \"$(echo "$VAR1" | sed -e 's/"/\\"/g')\""
>>
>> Which I verified with this:
>>
>> VAR1='Fred'\''s "boo" scared me!'
>>
>>
>>
>>
>>>
>>>
>>> --
>>> Mark J. Reed <email@hidden>
>>>
>>
>>
>>
>> --
>> Mark J. Reed <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
>>
>
>
--
Mark J. Reed <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