
我正在運行 OS X,我想知道是否有辦法取得 Finder 中目前標記檔案的路徑。
例如,UNIX 可以確定我點擊了哪個檔案嗎?
這樣做的原因是,例如,我可以建立一個執行 shell 腳本的服務,這樣當我右鍵單擊一個檔案時,我可以選擇「建立符號連結」或類似的內容。
ln -s path/to/currently/marked/file path/to/currently/marked/file_symlink
您還可以用它做很多其他事情。
答案1
這應該可以做到:
osascript -e 'tell application "Finder" to get POSIX path of (selection as string)'