在AppleScript中获取文件的网络地址

时间:2010-04-08 14:25:39

标签: applescript

我们是Mac电脑的网络。我想向同事发送电子邮件地址,并提供网络位置文件的链接。我制作了以下AppleScript:

tell application "Finder"
  set uuu to URL of the first item of (get the selection)
  set the clipboard to uuu
end tell

将当前所选文件的URL放入剪贴板,然后将其粘贴到消息中(使用“添加链接”菜单项),例如:

 file://localhost/Volumes/Commerciale/Clienti/

不幸的是这些链接不起作用。如果我从菜单项中选择“转到文件夹”,我可以使用 afp:// 类型的URL访问该文件夹。

有没有办法通过AppleScript获得这个,就像我上面的URL一样?

4 个答案:

答案 0 :(得分:2)

我用这个脚本解决了:

on urlToPOSIXPath(theURL)
    return do shell script "python -c \"import urllib, urlparse, sys; print urllib.unquote(urlparse.urlparse(sys.argv[1])[2])\" " & quoted form of theURL
end urlToPOSIXPath

tell application "Finder"
    set uuu to URL of the first item of (get the selection)
    set pp to my urlToPOSIXPath(uuu)
    set the clipboard to "file://" & pp
end tell

答案 1 :(得分:1)

卷是否已安装在电子邮件收件人的Mac上? Netlink创建一个可在Mail中单击的URL。我在这里没有AFP分享来测试这个:

tell application "Finder" to set netlink to URL of (get selection as alias)

答案 2 :(得分:0)

据我所知,不是“自动”。 URL和POSIX路径属性仅返回共享目录,而不返回卷本身。如果您使用Applescript为您提供的URL,则只有Applescript仍可以解析它。 (我得到的印象是操作系统或Applescript正在迭代已安装的卷找到文件)你需要操纵路径字符串以获得所需的格式。

答案 3 :(得分:0)

这是markratledge的帖子

的扩展版本
  tell application "Finder"  to set netlink to URL of (get  selection as alias)

  tell application "Mail"
     launch
     set newMessage to make new outgoing message with properties {subject:"network link", content:netlink, visible:true}

     -- Add in code for recipient, etc, etc
     --send newMessage
  end tell

但是这似乎仍然无效lol

相关问题