【问题标题】:How do I open a Finder sidebar folder via AppleScript?如何通过 AppleScript 打开 Finder 侧边栏文件夹?
【发布时间】:2010-09-23 23:44:39
【问题描述】:

我有一个 bash 脚本,它将通过 ssh 在 Mac 上运行。该脚本需要已安装特定的网络驱动器。在 Mac 上,我通过在 Finder 中打开该驱动器上的文件夹“JPLemme”来安装该驱动器。这会安装驱动器,直到 Mac 晚上进入睡眠状态。

显然,Finder 不能通过 ssh 使用,所以我想创建一个 AppleScript 来模拟我通过 GUI 所做的事情。我试过了:

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

我收到以下错误:

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

我认为我遗漏了一些明显的东西,但 Google 让我失望了。我也愿意接受更好的解决方案,例如直接安装驱动器;我已经避免了这种方法,因为我不希望 Mac 在我以意想不到的方式安装驱动器后再次尝试安装驱动器时窒息。 (我不太喜欢 Mac 或 AppleScript……)

【问题讨论】:

    标签: bash macos applescript finder


    【解决方案1】:

    您的网络卷应该有一个以某种方式附加到它的域。所以,“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
    

    您可以根据需要对其进行清理,但这是它的核心。祝你好运

    【讨论】:

      【解决方案2】:

      在它的核心,真正需要的是以下内容:

      Tell Application "Finder"
         Mount Volume "smb://username:password@server/sub/directory"
      End Tell
      

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

      【讨论】:

        猜你喜欢
        • 2012-06-30
        • 2013-02-06
        • 2010-09-27
        • 1970-01-01
        • 2021-01-10
        • 2023-02-26
        • 1970-01-01
        • 2011-10-10
        • 1970-01-01
        相关资源
        最近更新 更多