【问题标题】:Automator / Applescript : how to get original from folder aliasAutomator / Applescript:如何从文件夹别名中获取原始文件
【发布时间】:2019-01-29 02:09:01
【问题描述】:

我正在尝试创建一个上下文菜单快捷方式,以便在 VS Code 中从原始项目或其别名打开文件/文件夹

到目前为止,我已经能够创建一个 Automator 服务,它:

  • 已选择接收:文件或文件夹
  • 在:任何应用程序运行
  • shell 脚本:

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

如何将其更改为也接受别名?

【问题讨论】:

    标签: applescript automator


    【解决方案1】:

    符号链接应该没问题,但是 Finder 别名通常不起作用,因为大多数 shell 实用程序将它们视为小数据文件并且不知道如何解释它们。一种解决方案是添加 Run 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 脚本

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-07
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多