2011-03-18 43 views
-1

因此我在YouTube上觀看了這個視頻(http://www.youtube.com/watch?v=l_PLHuhlAJU),瞭解如何創建數據庫。我喜歡這個主意,但我不能讓它工作。數據庫中的applescript/xcode

誰能幫助我

P.S你也可以告訴我如何在Xcode做到這一點:-)

+0

建立在Xcode數據庫?祝你好運,我希望你... – 2011-03-18 21:53:36

+1

你不指定它如何不工作。它不會編譯?它沒有給出預期的結果嗎?如果您在提供AppleScript時遇到問題,那麼跳入Xcode可能不明智(儘管您可以在Xcode中構建AppleScript應用程序)。現在只需使用腳本編輯器並嘗試獲取它的一部分工作。 – Chuck 2011-03-18 23:45:21

回答

2

爲了擴大Anne的評論,這裏有一個更容易和更高效的數據庫。在腳本的頂部創建數據庫。您只需在那裏添加和刪除數據庫中的記錄。其餘代碼只是搜索數據庫並顯示結果。

請注意,數據庫中的一條記錄如下所示,在擴展數據庫時只需添加和刪除記錄。 {PERSONNAME: 「山姆·普萊斯」,memberNumber: 「1」,電話號碼: 「123」}

set myDatabase to {{personName:"Sam Price", memberNumber:"1", phoneNumber:"123"}, {personName:"Dave Blogg", memberNumber:"2", phoneNumber:"1234"}, {personName:"jack tumb", memberNumber:"3", phoneNumber:"12345"}} 

set x to text returned of (display dialog "Search for a member" default answer "ENTER THE NAME HERE!" buttons {"Search"} default button 1) 

set foundRecord to missing value 
repeat with aRecord in myDatabase 
    ignoring white space 
     ignoring case 
      if (personName of aRecord) contains x then 
       set foundRecord to aRecord 
       exit repeat 
      end if 
     end ignoring 
    end ignoring 
end repeat 

if foundRecord is missing value then 
    set dialogText to "The person \"" & x & "\" cannot be found in the database!" 
else 
    set dialogText to (personName of foundRecord) & ", member number: " & (memberNumber of foundRecord) & ", phone number: " & (phoneNumber of foundRecord) 
end if 

display dialog dialogText buttons {"OK"} default button 1 
1

這個視頻討論的腳本在視頻註釋粘貼。它不能正常工作,因爲所有新行字符都被Youtube刪除。我改變了代碼以按預期工作。將下面提到的代碼複製到AppleScript Editor並點擊運行,它現在應該可以正常工作。

請注意這是不是數據庫。該腳本僅獲取您的輸入並將其與一些預定義值逐一比較。當馬赫出現時,它會顯示一個對話框。

說明:
此代碼非常難看。你最好學習使用循環和列表。這使得你的代碼更高效。

set s to "sam price" 
set d to "dave blogg" 
set j to "jack tumb" 
set m to "max dog" 
set f to "fabio james" 
set sa to "sara parker" 
set o to "oliver jones" 
set b to "bob samuel" 
set x to text returned of (display dialog "Search for a member" default answer "ENTER THE NAME HERE!" buttons {"Search"} default button 1) 
ignoring white space 
    ignoring case 
     if x contains s then 
      display dialog "Sam Price, member number: 1, phone number: 123" buttons {"OK"} 
     end if 
     if x contains d then 
      display dialog "Dave Blogg, member number: 2, phone number: 1234" buttons {"OK"} 
     end if 
     if x contains j then 
      display dialog "jack tumb, member number: 3, phone number: 12345" buttons {"OK"} 
     end if 
     if x contains m then 
      display dialog "Max Dog, member number: 4, phone number: 12345" buttons {"OK"} 
     end if 
     if x contains f then 
      display dialog "Fabio James, member number: 5, phone number: 123456" buttons {"OK"} 
     end if 
     if x contains sa then 
      display dialog "Sara Parker, member number: 6, phone number: 1234567" buttons {"OK"} 
     end if 
     if x contains o then 
      display dialog "Oliver Jones, member number: 7, phone number: 12345678" buttons {"OK"} 
     end if 
     if x contains b then 
      display dialog "Bob samuel, member number: 8, phone number: 12345678" buttons {"OK"} 
     end if 
    end ignoring 
end ignoring