1

bash スクリプトの osascrip 行に小さな問題があります。Applescript の「リストから選択」ダイアログを介して bash スクリプトが呼び出され、if [[ $* = *"Option 1... selection タグを介してオプションを定義できます。

友人が私に osascript 行をくれました。「ファイルを選択」ダイアログが表示され、物事を選択するために機能しますが、「キャンセル」ボタンも「ファイルを選択」ダイアログをトリガーします。

OKとキャンセルの両方がファイルの選択ダイアログをトリガーするため、osascript行が最後近くでどこか不完全であると感じます。

bash スクリプトでは次のようになります。

#!/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...

osascript 行でキャンセル オプションが欠落している場所と、それを実装する方法を教えてください。

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 に答える