Cancel button on osascript in a bash script
i have a small Problem with a osascrip line in a bash script. The bash script gets called via a Applescript 'choose from list' dialogue, and then you can define options via a if [[ $* = *"Option 1... selection tag.
A friend gave me the osascript line, the 'choose a file' dialogue shows up and it works for choosing things, however the 'cancel' button also triggers the 'Choose a file' dialogue.
I feel the osascript line is somewhere incomplete near the end because both OK and cancel trigger the choose a file dialogue.
looks like this in a bash script:
#!/bin/bash
WORKDIR="$(dirname "$0")/"
STARTUPFILE="$(/usr/bin/osascript -e "tell application \"System Events\" to activate" -e "tell application \"System Events\" to set thefile to choose file with prompt \"Choose something here\"" -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Un开发者_JAVA技巧icode text)&\"\")")"
if [[ $* = *"Option 1 from Applescript"* ]]; then
cp -R "$STARTUPFILE/" "somewhere else"
do other stuff with "$STARTUPFILE...
Any idea where the cancel option is missing in the osascript line and how i could implement it?
Here's how to use a "choose from list" dialog. Note how we "error -128" when cancel is pressed...
set theList to {"yes", "no", "maybe"}
choose from list theList with title "Choose From The List" with prompt "PickOne" default items "maybe" OK button name "Select" cancel button name "Quit"
tell result
if it is false then error number -128 -- cancel
set choice to first item
end tell
精彩评论