2010-11-29 58 views
0

我在bash脚本中有一个小的osascrip行问题。 bash脚本通过Applescript的“从列表中选择”对话框调用,然后你可以通过if [[$ * = *“Option 1 ...选择标签来定义选项。在bash脚本中的osascript上取消按钮

一位朋友给了我一个osascript行,“选择文件”对话框显示出来,它可以用于选择事物,但是“取消”按钮也会触发“选择文件”对话框。

我觉得osascript行在末尾不完整,都OK并取消触发选择文件对话框。

看起来像这样在一个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行中缺少取消选项,以及我可以如何实现它?

回答

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