2010-03-05 76 views
0

的啓動腳本波紋管安裝在我的MacBook網絡驅動器:設置過期時間,當腳本嘗試安裝網絡驅動器

try 
    tell application "Finder" 
    mount volume "afp://iMac-01._afpovertcp._tcp.local/Backup%20HD" 
    end tell 
end try 

有兩個問題劇本對我來說:

  • 如果我離開網絡驅動器所在的本地網絡,該腳本需要很長時間才能嘗試連接,並且使得我的Macbook在初始化過程中緩慢。那麼,如何設置腳本的最大時間嘗試連接網絡驅動器?

  • 如果網絡驅動器無法連接,會彈出一條警告消息。如何忽略此消息?即使它不出現。

我從來沒有做過蘋果腳本之前,所以請,如果可能,請幫助我修改原始腳本。

在此先感謝。

回答

1

使用 '與timout'

try 
    with timeout of x seconds 
     tell application "Finder" 
      mount volume "afp://iMac-01._afpovertcp._tcp.local/Backup%20HD" 
     end tell 
    end timeout 
end try 
+0

該腳本忽略超時並需要大約2分鐘發送警告。與之前相同的東西。 :( – reinaldoluckman 2010-03-06 03:07:10

+0

你接受了我的回答,那麼你的工作對你來說還是需要修改我的代碼? – mcgrailm 2010-03-22 13:03:55

0

爲您解答: 1:超時爲mcgrailm國家使用;但是儘量只寫

with timeout of 2 second --no plural 
    <your code here> 
end timeout 

2:在彈出的對話框取景器彈出,因此你的腳本不能看到的是,「嘗試錯誤」不會被調用的錯誤永遠不會返回到腳本,所以如果你想自動點擊確定,那麼這個代碼將起作用。此代碼將在超時秒後點擊該按鈕。

try 
    <your code here> 
on error 
    tell application "System Events" 
     keystroke return 
    end tell 
end try 

我也包括我的版本,我在家裏使用這個腳本執行網絡的檢查同樣的想法的,然後嘗試安裝使用shell安裝卷。我最初使用了一個超時發現器「掛載音量」,並且這些代碼也作爲內嵌評論存在,但我不喜歡彈出錯誤對話框;即使只有一秒鐘,所以我轉向shell腳本。

-------------------------------------------------------------------------------------- 
--"Basic Drive Mounter.app" 
try 
    set IP_address to "xxx.xxx.xxx.xxx" 

    set IP_Valid to true 

    try 
     do shell script ("ping -c 2 " & IP_address) 
    on error 
     set IP_Valid to false 
    end try 

    if IP_Valid then 
     tell application "Finder" 
      if disk "work" exists then 
      else 

       try 
        do shell script "mkdir /Volumes/work" 
       end try 

       do shell script "mount_afp afp://xxx.xxx.xxx.xxx/work /Volumes/work/" 

       -->>finder mount volume version 
       --with timeout of 2 second 
       -- mount volume "afp://xxx.xxx.xxx.xxx/work" 
       --end timeout 
       --<<finder mount volume version 
      end if 
     end tell 
    end if 
on error 
    return 0 

    -->>finder mount volume version 
    --on error finder returns an error dialog which needs to be closed to go back and retry 
    --tell application "System Events" 
    -- keystroke return 
    --end tell 
    --<<finder mount volume version 
end try  
-------------------------------------------------------------------------------------- 
相關問題