Hi,
I came up with this and of course it isn’t working.
Please can someone guide me to what I have to change?
It reads file from a dir get the file path.
Creates a list like “item1”,“item2”,“item…n” for the applescript way, right??
Pass it to osascript and shows a dialog.
P.s I need later the file list again in the bash script.
for file in ${ProjectTemplateFolder}/*
do
f=${file##*/}
if [ “${f:0:1}” = " " ] ; then
echo “NOT Processing $f” 1>&2 # for now just a test
else
if [[ ! -z ${ItemList} ]] ; then
ItemList=${ItemList}“,”
fi
echo “Processing $f” 1>&2
ItemList=${ItemList}“"”${f}“"” # to create “item1”,“item2”,“item…n”
fi
done
echo “ItemList :”${ItemList}
_result=/usr/bin/osascript << CHOICELIST tell app "System Events" Activate set res to (choose from list {'"$ItemList"'} with prompt "Choose a File:" OK button name "Select" cancel button name "Quit") return res end tell CHOICELIST
Or should I go for something like
to get a kind of escaped list?
Basically, how can I pass list from bash to applescript?
Thank you.
Hi,
This is working.
But still curious why the former code isn’t working and what I should change.
I think it has something to do with this.
Quote style you used:
[i]applescript=‘tell application “Finder”\n’;
applescript=‘$applescript display dialog “hello world”\n’;
applescript='$applescript end tell";
echo $applescript | osascript[/i]
This doesn’t work because when using a single-quote-style string in bash you can’t use var names in it.
http://www.gnu.org/software/bash/manual/bashref.html#Double-Quotes:
Enclosing characters in single quotes (˜’') preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.
So use double quoted instead
[i]applescript=“tell application "Finder"\n”;
applescript=“$applescript display dialog "hello world"\n”;
applescript=“$applescript end tell”;
echo $applescript | osascript[/i]