[SVN] Passing variables to osascript, or other workaround?

Charilaos Skiadas cskiadas at uchicago.edu
Wed May 11 22:53:15 UTC 2005

On May 11, 2005, at 4:55 PM, Allan Odgaard wrote:

> On May 11, 2005, at 22:58, Charilaos Skiadas wrote:
>> My problem basically is: how can I pass a list of strings to 
>> osascript, so that it can perceive them as a list, and so that 
>> "choose from list" would work as expected. I am clearly 
>> misundestanding something. The script I was trying is:
> I think the problem was something with the list containing illegal 
> (according to AS) characters, probably it had \ in front of the quotes 
> (looking at your pattern).

Yeah, I had it without the \ in front, but that didn't go too well 
> I took the library to use perl instead of sed, because it has an IMHO 
> much better regex grammar (and more capabilities), I also changed 
> stdin for the command to be “entire document” so grep can just work on 
> that instead of TM_FILEPATH, plus let awk write result to stdout 
> directly rather than go through a variable:
> list=`grep '\\label{.*}'|perl -pe 's/.*\\label\{(.*?)\}(.*)\n/"$1 : 
> $2",/'`
> res=`osascript <<EOF
> 	tell application "System Events"
> 		activate
> 		choose from list { ${list:0:${#list}-1} }
> 	end tell
> EOF`
> osascript -e 'tell app "TextMate" to activate' &>/dev/null &
> awk <<<$res '{ printf("%s", $1) }'

Neat! It works great if I remove the ': $2' part above. If I have it in 
though, it produces:
200:201: syntax error: Expected “"” but found unknown token. (-2741)

The part matched by $2 is basically the rest of the line where the 
\label occurs, so that the user has a context and can figure out better 
what label they want. So it is a whole LaTeX line, with lots of 
unescaped \'s. So I added the line:
above the res=`osascript...
Now it works properly, but it took unacceptably long, I'm guessing 
because the lines might be pretty long. Is there any way to speed it 
up? I tried adding a line:
list="${list:0:80}" before the above assignment to show only a 
reasonable part of the rest of the line (btw, can I combine them in one 
step? the obvious way didn't work.) but that took me back to the 
previous error. Is there something else I might need to escape, maybe 
braces or something? (i.e. when I cut at the 80 characters, maybe I've 
left some braces unended?)
For now I'll remove the ': $2' part and add it to the repository.

In terms of scope, this is to be used inside a \ref{} or an \eqref{} 
(can't remember if there are others). would the proper scope be 
text.latex, declaration.ref-or-label.latex or 
keyword.control.ref-or-label.latex ?

> Btw: questions like these should be sent to the normal user list.

Sorry. Will keep that in mind for next time.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 2733 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate-dev/attachments/20050511/fae291a9/attachment.bin>

More information about the textmate-dev mailing list