[英]How do I open a Finder sidebar folder via AppleScript?
我有一个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)
我认为我错过了一些明显的东西,但谷歌让我失望了。 我也愿意接受更好的解决方案,比如直接安装驱动器; 我已经避免了这种方法,因为我不希望Mac在我以意想不到的方式安装它之后第二次尝试安装驱动器。 (我真的不喜欢Macs或AppleScript ...)
您的网络卷应该附加某种域名。 所以,“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
您可以根据需要进行清理,但这是它的核心。 祝好运
在它的核心,真正需要的是以下内容:
Tell Application "Finder"
Mount Volume "smb://username:password@server/sub/directory"
End Tell
但是使用的内容在很大程度上取决于网络环境和返回的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.