2008-11-25 123 views
4

我有一個bash腳本,它將通過ssh在Mac上運行。該腳本需要一個特定的網絡驅動器已被掛載。在Mac上,我通過在Finder中的該驅動器上打開一個文件夾「JPLemme」來安裝此驅動器。這將驅動器安裝到Mac在夜間進入睡眠狀態。如何通過AppleScript打開Finder邊欄文件夾?

顯然,Finder不能通過ssh使用,所以我想創建一個AppleScript,它將模擬我通過GUI執行的操作。我已經試過:

tell application "Finder" 
activate 
open "JPLemme" 
end tell 

我收到以下錯誤:

execution error: Finder got an error: Can't get "JPLemme". (-1728) 

我想我失去了一些東西明顯,但谷歌已經讓我失望。我也願意接受更好的解決方案,如直接安裝變頻器;我已經避免了這種做法,因爲我不希望Mac在我已經以意想不到的方式裝入驅動器後再次嘗試裝入驅動器。 (我不太喜歡Mac或AppleScript ...)

回答

2

你的網絡卷應該有一個附加到某種類型的域。所以,「JPLemme.domain.com」。我用下面的代碼塊獲取到該密碼保護的網絡容量:

tell application "Finder" 
     try 
      set theServer to mount volume "smb://path/to/volume" as username "YourUserName" with password "YourPassword" 
--Please note here that this is a plain string without any built-in security. Use at your own risk. 
     on error 
      set VolumeCount to (get count of disks) 
      repeat with x from 1 to VolumeCount 
      set thisVolume to disk x 
      if name of thisVolume is "JPLemme" then 
       set theServer to thisVolume 
       exit repeat 
      end if 
      end repeat 
     end try 
    end tell 

您可以根據需要清理,但是這是它的核心。祝你好運

1

在這是非常核心的,所有真正需要的是以下幾點:

Tell Application "Finder" 
    Mount Volume "smb://username:[email protected]/sub/directory" 
End Tell 

但什麼是使用將在很大程度上取決於網絡環境和錯誤返回。

相關問題