代码之家  ›  专栏  ›  技术社区  ›  João Otero

automator/applescript:如何从文件夹别名获取原始文件

  •  0
  • João Otero  · 技术社区  · 6 年前

    我正在尝试创建上下文菜单快捷方式,以从原始项或其别名在vs代码中打开文件/文件夹

    到目前为止,我已经能够创建一个可滚动的服务,它:

    • 接收选定的:文件或文件夹
    • in:任何应用程序运行
    • 外壳脚本:

    open -n -b "com.microsoft.VSCode" --args "$*"

    我怎样才能改变它接受别名呢?

    1 回复  |  直到 6 年前
        1
  •  1
  •   red_menace    6 年前

    符号链接应该没问题,但finder别名通常不起作用,因为大多数shell实用程序将它们视为小数据文件,不知道如何解释它们。一个解决方案是添加 运行applescript 在输入中查找别名并改用原始项的操作,例如:

    • 已选择服务接收 文件或文件夹 在里面 任何申请
    • 运行applescript :

      on run {input, parameters}
        set output to {} -- this will be a list of the output items
        tell application "Finder" to repeat with anItem in the input
          if anItem's kind is "Alias" then
            set the end of output to POSIX path of (original item of anItem as alias)
          else
            set the end of output to POSIX path of anItem
          end if
        end repeat
        return output
      end run
      
    • 运行shell脚本