代码之家  ›  专栏  ›  技术社区  ›  JPLemme

如何通过AppleScript打开Finder边栏文件夹?

  •  4
  • JPLemme  · 技术社区  · 16 年前

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

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

    我收到以下错误:

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

    2 回复  |  直到 16 年前
        1
  •  3
  •   Philip Regan    16 年前

    您的网络卷应具有某种类型的连接域。所以,“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
  •  1
  •   Philip Regan    16 年前

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

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