2016-06-07 89 views
0

如果我在本地或远程服务器上的查找程序中选择一个文件,我希望脚本将POSIX路径作为文本粘贴到剪贴板,以便粘贴在聊天窗口等在Applescript中:将所选文件的POSIX路径复制到剪贴板

这是我迄今为止,但它是不是很干净:

on run 
    tell application "Finder" 
     copy selection to theSelected 
     set outputPathList to {} 
     set anItem to theSelected 
     copy (POSIX path of (anItem as alias)) to end of outputPathList 

     set AppleScript's text item delimiters to return 
     set outputString to outputPathList as string 
     set AppleScript's text item delimiters to "" 

     set the clipboard to outputString 
    end tell 
end run 

如何清理它的任何想法?

回答

0

Finder的属性selection返回Finder说明符列表。
该脚本将所有POSIX路径(每行一个)复制到剪贴板。

tell application "Finder" to set theSelection to (get selection) 
if theSelection is {} then return 
set outputPathList to {} 
repeat with anItem in theSelection 
    set end of outputPathList to POSIX path of (anItem as text) 
end repeat 
set {TID, text item delimiters} to {text item delimiters, return} 
set the clipboard to outputPathList as text 
set text item delimiters to TID 
+0

是否有可能把它输出一个可点击的链接(例如“文件://卷/ SOME_HD /文件夹/文件夹/文件”) –

+0

要获得有关文件方案的网址只是把方案中的前将outputPathList的结尾设置为“file://”的POSIX路径(作为文本的anItem)' – vadian

+0

谢谢。我无法得到我的结尾写字眼。你是一个很好的帮助。 –

1
on run 
    tell application "Finder" 
     set theItem to selection as string 
    end tell 
    set posixForm to POSIX path of theItem 
    set the clipboard to posixForm 
end run