2008-11-25 122 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 

但什么是使用将在很大程度上取决于网络环境和错误返回。

相关问题