2014-03-25 44 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

相关问题