This is just driving me nuts. I am trying to read a file in bash, remove duplicates, sort, and then display a "list choice" window via applescript.
My $DATALOG file is formatted like this:
field1 field2
field1 field3
field1 field4
etc...
Applescript=awk '{print $2}' $DATALOG | awk ' !x[$0]++' | sort -u | tr "_" " "| sed 's/^/\"/' | sed 's/$/\"/' | tr "\n" "," | sed 's/.$//'
Now, that line works GREAT. in $Applescript, I get an output like this:
"field 2","field 3", "field 4"
Which is exactly waht I want.
Now, I take that output, and add the backslash before the quotes, and the applescript parts.
Applescript=`echo "tell application \"System Events\" to return (choose from list {$Applescript})"| sed 's/\"/\\\"/g'`
And this gets me exactly what I want:
tell application \"System Events\" to return (choose from list {\"field 2\",\"field 3\",\"field 4\"})
Now, I try the osascript command:
osascript -e $Applescript
And I get an error:
4:4: syntax error: Expected expression but found end of script. (-2741)
So, I add quotes:
osascript -e "$Applescript"
And I get an error:
17:18: syntax error: Expected expression, property or key form, etc. but found unknown token. (-2741)
I can't tell what the hell's going on here, so I decide to COPY an echo of $Airport and try that as a variable.
Airport=
tell application \"System Events\" to return (choose from list {\"field 2\",\"field 3\",\"field 4\"})
AND THAT WORKS WITHOUT ANY MODIFICATION.
So....
I need to figure out how to do this without having to set my variables permanently.