获取信息对话框中有一个服务器字段,如下图所示:
有没有办法将它分配给Applescript中的变量?
我写了一个脚本如下:
tell application "System Events"
set disk_list to the server of disks
repeat with a_disk in disk_list
display dialog a_disk
end repeat
end tell
所有对话框均显示“msng”。 😅
我能想到的唯一方法如下面的代码所示,但需要注意的是,我没有广泛的网络驱动器或服务器来测试它在返回所需路径时的有效性或可靠性。 事实上,我只设法在我可以为自己创建的一个用例的上下文中测试它:我将 iMac 的
~/Music
文件夹共享为 samba 文件夹共享,并将其安装在 /Volumes/Music
在我的 MacBook 上。
use framework "Foundation"
use scripting additions
-------------------------------------------------------------------------
property key : "NSURLVolumeURLForRemountingKey"
-------------------------------------------------------------------------
to resolveURLForFile at path as text
global key
tell the resourceValuesForKeys_error_([key], missing value) ¬
of the fileURLWithPath_(stringByStandardizingPath() ¬
of my (NSString's stringWithString:path)) of my the ¬
NSURL to if it is not missing value then return the ¬
valueForKey_(key)'s absoluteString() as text
end resolveURLForFile
---------------------------------------------------------------------⟨!#⟩
我的测试运行如下:
resolveURLForFile at "/Volumes/Music"
返回的输出为:
"smb://CK@CK-mac._smb._tcp.local/Music"
让我知道它对你来说效果如何,如果结果有任何好处,请投票/选择这个答案。