Che*_*het 2 applescript automator
我希望能够在Finder中右键单击文件或文件夹,然后选择服务>打开终端以在该路径上打开终端窗口.
在automator中,我有一个运行AppleScript的服务
tell application "Terminal"
do script "cd $filePath"
activate
end tell
Run Code Online (Sandbox Code Playgroud)
我不知道如何传递文件路径!
额外奖励:我如何确保这适用于文件和文件夹?如果是一个文件,可能会说该文件不是目录.
额外奖励:我自己哪里可以找到这个答案?文档似乎是密集的方式.
谢谢
切特
请注意顶部的"服务接收选定的...",这会给出AppleScript的结果.这将打开文件夹和文件容器,但不会冗余.

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
Run Code Online (Sandbox Code Playgroud)
[编辑:]顺便提一下,还有一件事要做,就是如何处理捆绑包,例如.app文件,这些文件不是真正的文件.运用
set i to info for (alias f)
Run Code Online (Sandbox Code Playgroud)
然后
package folder of i
Run Code Online (Sandbox Code Playgroud)
将通过一个额外的if/then分支使脚本能够确定这一点.我个人不介意它"cd"成捆绑.
| 归档时间: |
|
| 查看次数: |
6667 次 |
| 最近记录: |