2016-06-07 46 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