2014-03-25 45 views
2

我希望能夠右鍵單擊Finder中的文件或文件夾,然後選擇服務>打開終端以在該路徑打開終端窗口。如何在Automator中將文件路徑傳遞給AppleScript?

在Automator中,我有一個運行一個AppleScript

tell application "Terminal" 
    do script "cd $filePath" 
    activate 
end tell 

我不知道如何傳遞文件路徑的服務!

獎勵:我如何確保這適用於文件和文件夾?如果它是一個文件,它可能會說該文件不是一個目錄。

獎勵:我可以在哪裏找到自己的答案?文件似乎是密集的方式。

感謝

切特

+0

(測試OSX 10.6.8 - 老,我知道,讓我知道如果你的版本,如果不同,不喜歡它) – CRGreen

回答

8

注意 「服務接收選擇......」 在頂部,這給了導致對AppleScript的。 這將打開文件的文件夾和容器,但不會是多餘的。 enter image description here

on run {input, parameters} 
    set didThese to {} 
    repeat with f in input 
     set f to (f as text) 
     if f ends with ":" then 
      if f is in didThese then --check to see if we did this already 
       --ignore 
      else 
       tell application "Terminal" to do script "cd " & quoted form of POSIX path of f 
       set didThese to (didThese & f) --load into memory for subsequent iterations of loop 
      end if 
     else 
      --first get containing folder, then use that 
      tell application "Finder" to set f to ((container of alias f) as alias as text) 
      if f is in didThese then 
       --ignore 
      else 
       tell application "Terminal" to do script "cd " & quoted form of POSIX path of f 
       set didThese to (didThese & f) 
      end if 
     end if 
    end repeat 
    activate application "Terminal" 
end run 

收集從https://apple.stackexchange.com/questions/112731/automator-service-to-print-a-relative-path-of-selected-files-printing-everything

[編輯:] 順便說一下,一兩件事沒有決定是如何看待的捆綁,像的.app文件,這不是真正的文件。使用

set i to info for (alias f) 

然後

package folder of i 

將使腳本確定這一點,通過一個附加的if/then分支。我個人不介意把它「捆綁」成捆。

+0

是的!謝謝。 – Chet

相關問題