2016-02-04 97 views
1

我正在做一個幫助學校的applescript。您鍵入您想要訪問的主題,然後打開該文件夾(在應用程序內)。然而,有些科目有電子書,所以我想在那裏有另一個對話框,詢問你是否想打開電子書或文件夾。不幸的是,一個display dialog不能分出另一個顯示對話框。指示應用程序在AppleScript中運行其他腳本。

到目前爲止,我發現的唯一方法是指導應用程序運行另一個腳本(在應用程序的「腳本」文件夾中)。我試過

tell application "Script Editor" to run script (path to me as sting) & "Contents:Resources:Scripts:Subject.scpt"` 

但它沒有奏效。對不起,如果我吠叫錯誤的樹,看起來完全愚蠢。謝謝

+0

你幾乎肯定不需要,也不應該完成這個調用額外的腳本。你是說你想同時激活兩個顯示對話框嗎?這是爲什麼?亞瑟的答案應該是你需要的。 – jweaks

回答

1

據我瞭解你想達到什麼,下面的腳本將工作。

set listOfSubjects to {"Math", "Biology", "History", "Languages"} 
set subjectsWithEbook to {"Biology", "History"} 

choose from list listOfSubjects with prompt "Select the subject" 
set subject to item 1 of result 

set openEbook to false 
repeat with subjectItem in subjectsWithEbook 
    if subjectItem contains subject then 
     choose from list {"Open folder", "Open Ebook"} with prompt "What to open?" 
     set openType to item 1 of result 

     if openType contains "Open Ebook" then 
      set openEbook to true 
     end if 
     exit repeat 
    end if 
end repeat 


if openEbook then 
    --Open ebook  
else 
    --Open folder 
end if 
+0

這非常接近我的目標,是的。我只是想從列表中選擇第一個顯示對話框。謝謝 –

0

我猜你想輸入主題名稱?這是一個使用對話框的例子。

set subjectFolderPath to (path to me as string) & "Contents:Resources:Subjects:" 
set subjectsWithEbook to {"English", "Spanish"} 

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 
    display dialog "Would you like to open the Folder or the Book?" buttons {"Folder", "Book"} default button 1 
    set toOpen to button returned of the result 
    if toOpen is "Book" then 
     -- tell app "Preview" to open ??? 
     beep 
    else 
     tell application "Finder" to open folder (subjectFolderPath & theSubject & ":") 
    end if 
else 
    tell application "Finder" to open folder (subjectFolderPath & theSubject & ":") 
end if 

您可能還想要一個允許的主題列表和錯誤檢查。

相關問題