1

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 Unicode 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?

4

1 回答 1

3

以下是如何使用“从列表中选择”对话框。请注意按下取消时我们如何“错误-128”......

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
于 2010-12-01T04:02:28.020 回答