from stdout to an applescript variable?

Well here’s the problem…
I’ve worked out how to assign the result of an applescript operation to a bash variable within a shell script;
foo=osascript -e 'some applescript opperation'

but i need to be able to do the opposite also.
how do i (within a shell script) get the result of a bash command line into a variable for applescript to play with?

To get the normal stdout result just do something like

set x to do shell script "ls"

To get the result code of an operation (0=success, non-0=failure) do something like

set x to do shell script "cp a b;echo $?"

Hope that’s what you’re looking for…

  • Dan

That doesn’t seem to work for me.

I’m trying to make a itunes controller through applescript but it needs have an interface of .sh files. (the point being to control iTunes over ssh).
And so I need to be able to (the middle of a shell script) transfer variable values between applescript one liners and the rest of the shell script and back.
For clarity’s sake here is what I’m currently working on


#!/bin/sh

if [ $# = 0 ]; then
    echo "syntax: toggleshuffle.sh playlist"
else

    if [ `osascript -e 'tell application "iTunes" to get shuffle of playlist "Rock"'` = `echo "true"` ]; then
        # This line is my best guess at how to do this but the do shell script bit doesn't seem to be able to see the $@ variable from the rest of the script
        osascript -e 'tell application "iTunes" to set shuffle of playlist (do shell script "echo $@") to false'
    else
        osascript -e 'tell application "iTunes" to set shuffle of playlist (do shell script "echo $@") to true'
    fi

fi

Is there any way around this problem???

Does

osascript -e 'tell application "iTunes" to set shuffle of playlist (do shell script "echo ' $@'") to false'

do the trick, i.e., place $@ outside the single quotes? I don’t script iTunes so I don’t understand the significance of $@ here, but if I just set z to XYZ and substitute $z for $@ in your script then (do shell script) doesn’t object, whereas it does if I don’t break up the command.

Just a thought…

(…and now looking back at your explanation you did show exactly what the function of $@ is so I understand what the script is doing now…PIMF.)

Thanks alot, it all works now :slight_smile:
btw $@ is the default internal variable for an argument for a sh script (and $# is the number of variables)