【问题标题】:Cancel button on osascript in a bash scriptbash脚本中osascript上的取消按钮
【发布时间】:2011-05-17 13:59:12
【问题描述】:

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

朋友给了我 osascript 行,“选择文件”对话框出现,它可以用于选择内容,但是“取消”按钮也会触发“选择文件”对话框。

我觉得 osascript 行在接近尾声的地方不完整,因为 OK 和 cancel 都触发了选择文件对话框。

在 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 行中哪里缺少取消选项以及如何实现它吗?

【问题讨论】:

    标签: macos bash dialog applescript osascript


    【解决方案1】:

    以下是如何使用“从列表中选择”对话框。请注意我们在按下取消时如何“错误 -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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-14
      • 1970-01-01
      • 2013-07-17
      • 2014-06-19
      • 1970-01-01
      • 2020-01-30
      • 1970-01-01
      • 2016-09-22
      相关资源
      最近更新 更多