对话结果从列表中选择后, [英] Dialog results after choose from lists

查看:113
本文介绍了对话结果从列表中选择后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了学校的脚本打开的文件夹和电子书所选科目。你输入你要访问的主题,然后它打开了主题为你(在应用程序的资源文件夹)的文件夹。然而,一些科目有电子书,所以我所做的脚本显示从列表中选择如果这个问题确实有一个。这种运作良好,我可以做从列表中选择两个结果,使作品。这是当我起床科目没有一个电子书(所以他们不需要从列表中选择),它简化版,工作。说,例如,戏剧没有一个电子书,所以如果我输入剧,它只会打开文件夹,立竿见影。这是我到目前为止;谁能告诉我,为什么它不工作:

 设置为subjectsWithEbook {历史,科学,数学,法国}显示对话框你喜欢什么科目来访问?默认回答
集theSubject以文本返回的结果如果theSubject是subjectsWithEbook然后
从列表{打开文件夹,打开电子书},进行提示选择怎么开?
设置theResult到结果的第1项
如果theResult是打开电子书和theSubject是历史,那么
    告诉应用程序野生动物园
        启用
        开位置
    告诉结束
其他
    如果theResult是打开文件夹和theSubject是历史,那么
        告诉应用程序发现者打开文件夹((路径,我作为字符串)及内容:资源:主题:历史)
    其他
        如果theResult是打开电子书和theSubject是科学,那么
            告诉应用程序野生动物园
                启用
                开位置
            告诉结束
        其他
            如果theResult是打开文件夹和theSubject是科学,那么
                告诉应用程序发现者打开文件夹((路径,我作为字符串)及内容:资源:主题:科学)
            其他
                如果theResult是打开电子书和theSubject是法国,那么
                    告诉应用程序野生动物园
                        启用
                        开位置
                    告诉结束
                其他
                    如果theResult是打开文件夹和theSubject是法国,那么
                        告诉应用程序发现者打开文件夹((路径,我作为字符串)及内容:资源:主题:法国)
                    其他
                        如果theResult是打开电子书和theSubject是数学,那么
                            告诉应用程序preVIEW打开(路径,我作为字符串)及内容:资源:maths_ebook.pdf
                        其他
                            如果theResult是打开文件夹和theSubject是数学,那么
                                告诉应用程序发现者打开文件夹((路径,我作为字符串)及内容:资源:科目:数学)
                            其他
                                如果theSubject包含戏剧,然后
                                    告诉应用程序发现者打开文件夹((路径,我作为字符串)及内容:资源:主题:话剧)
                                万一
                            万一
                        万一
                    万一
                万一
            万一
        万一
    万一
万一
万一


解决方案

要与所有的情况下适应,甚至更多,我更新了我的第一个脚本,使用记录的数据结构如前​​所述。

您现在可以定义你想尽可能多的科目,并为每个,文件夹打开(如果有的话),或电子书。对于电子书,还可以定义应用程序用来打开:例如,如果电子书记录包含URL可能是preVIEW的PDF文件,或Safari。

在我为例,我补充说,戏剧,一个txt文件,必须通过文本编辑打开。

有关数学,这是通过preVIEW要打开一个PDF

有关历史,这是一个URL(谷歌!)是通过Safari打开。

这只是告诉你,你可以用这个新的脚本做任何事情。
(我增加了许多评论)

 (*每个记录包含4个值:有,因为你需要尽可能多的记录
  子:被检体的名称
  EB:URL或电子书的文件名。如果没有空电子书
  FOL:从内容的文件夹的名称/资源是开放的。如果为空,没有文件夹打开
  EBApp:应用程序,以用于打开的EB。
          在本例使用数学preVIEW,戏剧使用texEdit和所有其他正在使用Safari浏览器
*)
全球myRules - 要使用也子程序 - 在这里填写您的所有定义的URL和文件
设置myRules为{{子:数学,EB:maths_ebook.pdf,FOL:数学,EBApp:preVIEW},{子:历史,EB:www.google.com FOL:历史,EBApp:野生动物园}}
设置myRules为myRules&安培; {{子:科学,EB:myURL,FOL:数学,EBApp:野生动物园},{子:法国,EB:www.apple.com,FOL:法国, EBApp:野生动物园}}
设置myRules为myRules&安培; {{子:戏剧,EB:Drama.txt,FOL:,EBApp:文字编辑}}
设置R显示对话框中的你喜欢什么科目来访问?默认回答按钮{打开文件夹,开放的电子书,取消}
设置theSubject首都(R文本返回) - 确保1个字母大写像subjectsWithEbook
设置theChoice为(R的返回键)
设置NumItem为ITEMLIST(theSubject)如果NumItem为0,那么 - 不知道如何处理这个问题不在列表中呢!
显示警报对不起,主题与& theSubject&安培; 不可用
返回
万一设置mySubject为myRules项目NumItem
如果(theChoice是打开文件夹)和(mySubject的FOL不是),那么
告诉应用程序发现者打开文件夹((路径,我作为字符串)及内容:资源:主题:及(mySubject的FOL))
万一如果(theChoice是打开电子书)和(mySubject的EB是),然后
显示警报对不起,主题与& theSubject&安培; 没有电子书版本
返回
万一如果(theChoice是打开电子书)和(mySubject的EB是不)和(mySubject的EBApp不是),那么
如果mySubject的EBApp是野生动物园,那么
    告诉应用程序野生动物园开的位置(mySubject的EB)
其他
    告诉应用程序(mySubject的EBApp)打开(mySubject的EB)
万一
万一在ITEMLIST(LSubject) - 返回myRules主体的项目编号
诉讼设置为0
与我重复1到(myRules计数)
    如果项目LSubject =子我myRules的然后设置为诉讼我
重复结束
返回诉讼
结束ITEMLIST资本(Localtext) - 坐落在首都和其他小型股1日的信。
设置来函Localtext的每个字符
与我再说一遍,从1数快报
    设置A到ASCII数(项目我快报)
    如果(I = 1)和(A> 96)和(A< 123),然后设置A到A - 32
    如果(I> 1)和(A> 64)和(A< 91),然后设置A到A + 32
    集信项目1到A的ASCII字符
重复结束
返回信函作为字符串
首都结束

I have written a script for school that opens folders and ebooks for selected subjects. You type the subject you want to access, then it opens the folder of that subject for you (in the resources folder of the app). However, some subjects have ebooks, so I've made the script show a choose from list if the subject does have one. This works well, and I can do both results from choose from list, so that works. It's when I get up to subjects without an ebook (so they don't require a choose from list) that it does't work. Say, for example, Drama doesn't have an ebook, so if I type "drama" it'll just open the folder straight away. This is what I have so far; can anyone tell me why it doesn't work?:

set subjectsWithEbook to {"History", "Science", "Maths", "French"}

display dialog "What subject would you like to access?" default answer ""
set theSubject to text returned of the result

if theSubject is in subjectsWithEbook then
choose from list {"Open folder", "Open eBook"} with prompt "What to open?"
set theResult to item 1 of the result
if theResult is "Open eBook" and theSubject is "history" then
    tell application "Safari"
        activate
        open location ""
    end tell
else
    if theResult is "Open folder" and theSubject is "history" then
        tell application "Finder" to open folder ((path to me as string) & "Contents:Resources:Subjects:History")
    else
        if theResult is "Open eBook" and theSubject is "science" then
            tell application "Safari"
                activate
                open location ""
            end tell
        else
            if theResult is "Open folder" and theSubject is "science" then
                tell application "Finder" to open folder ((path to me as string) & "Contents:Resources:Subjects:Science")
            else
                if theResult is "Open eBook" and theSubject is "french" then
                    tell application "Safari"
                        activate
                        open location ""
                    end tell
                else
                    if theResult is "Open folder" and theSubject is "french" then
                        tell application "Finder" to open folder ((path to me as string) & "Contents:Resources:Subjects:French")
                    else
                        if theResult is "Open eBook" and theSubject is "maths" then
                            tell application "Preview" to open (path to me as string) & "Contents:Resources:maths_ebook.pdf"
                        else
                            if theResult is "Open folder" and theSubject is "maths" then
                                tell application "Finder" to open folder ((path to me as string) & "Contents:Resources:Subjects:Maths")
                            else
                                if theSubject contains "Drama" then
                                    tell application "Finder" to open folder ((path to me as string) & "Contents:Resources:Subjects:Drama")
                                end if
                            end if
                        end if
                    end if
                end if
            end if
        end if
    end if
end if
end if

解决方案

To accommodate with all your cases, and even more, I updated my first script, using the records data structure as explained before.

You can now define as many subjects you want, and for each, the folder to open (if any), or the ebook. For the ebook, you can also define the application to be used to open: for instance, it could be "Preview" for a PDF file, or Safari if the ebook record contains URL.

In my exemple, I added, for Drama, a txt file which must the open via TextEdit.

For Maths this is a pdf to be opened via Preview

For History, this is an URL (google !) to be open via Safari.

This is just to show you that you can do anything with this new script. (I have added many comments)

(* each record contains 4 values : there are as many records as you need
  Sub : the name of the subject
  EB  : the URL or filename of the ebook. if empty no ebook
  Fol : the name of the folder from Contents/Resources to be open. if empty,no folder to open
  EBApp : the application to be used to open EB. 
          In this exemple Maths uses "Preview", Drama uses texEdit and all others are using Safari
*)
global myRules -- to be use also in sub-routines

-- fill here all your definitions URLs and documents
set myRules to {{Sub:"Maths", EB:"maths_ebook.pdf", Fol:"Maths", EBApp:"Preview"}, {Sub:"History", EB:"www.google.com", Fol:"History", EBApp:"Safari"}}
set myRules to myRules & {{Sub:"Science", EB:"myURL", Fol:"Maths", EBApp:"Safari"}, {Sub:"French", EB:"www.apple.com", Fol:"French", EBApp:"Safari"}}
set myRules to myRules & {{Sub:"Drama", EB:"Drama.txt", Fol:"", EBApp:"TextEdit"}}


set R to display dialog "What subject would you like to access?" default answer "" buttons {"Open folder", "Open ebook", "Cancel"}
set theSubject to Capital(text returned of R) -- make sure 1 letter capital like in subjectsWithEbook
set theChoice to (button returned of R)
set NumItem to ItemList(theSubject)

if NumItem is 0 then -- don't know what to do with this subject not in the list !
display alert "Sorry; Subject " & theSubject & " is not available"
return
end if

set mySubject to item NumItem of myRules
if (theChoice is "Open folder") and (Fol of mySubject is not "") then
tell application "Finder" to open folder ((path to me as string) & "Contents:Resources:Subjects:" & (Fol of mySubject))
end if

if (theChoice is "Open ebook") and (EB of mySubject is "") then
display alert "Sorry; Subject " & theSubject & " has no ebook version available"
return
end if

if (theChoice is "Open ebook") and (EB of mySubject is not "") and (EBApp of mySubject is not "") then
if EBApp of mySubject is "Safari" then
    tell application "Safari" to open location (EB of mySubject)
else
    tell application (EBApp of mySubject) to open (EB of mySubject)
end if
end if

on ItemList(LSubject) -- return the item number of the subject in myRules
set LItem to 0
repeat with I from 1 to (count of myRules)
    if LSubject = Sub of item I of myRules then set LItem to I
end repeat
return LItem
end ItemList

on Capital(Localtext) -- set 1st letter in capital and other small caps.
set Letters to every character of Localtext
repeat with I from 1 to count of Letters
    set A to ASCII number of (item I of Letters)
    if (I = 1) and (A > 96) and (A < 123) then set A to A - 32
    if (I > 1) and (A > 64) and (A < 91) then set A to A + 32
    set item I of Letters to ASCII character of A
end repeat
return Letters as string
end Capital

这篇关于对话结果从列表中选择后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆