开发者

Cancel button on osascript in a bash script

开发者 https://www.devze.com 2023-01-28 01:24 出处:网络
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

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
0

精彩评论

暂无评论...
验证码 换一张
取 消