【问题标题】:AppleScript path relative to script locationAppleScript 相对于脚本位置的路径
【发布时间】:2015-09-08 09:52:37
【问题描述】:

我正在尝试启动与我的脚本位于同一目录中的文件夹的 Finder 窗口。当我运行下面的代码时,它会启动一个空白的 Finder 窗口,该窗口设置为脚本路径而不是文件夹。

tell application "Finder"
    tell application "Finder" to make new Finder window
    set file_path to (path to me) as text
    set target of Finder window 1 to file_path
end tell

如何获取脚本文件夹的路径,而不是脚本?

【问题讨论】:

标签: macos path applescript finder


【解决方案1】:

你很亲密。您不需要文件的文本版本,您只需要文件本身,然后您可以向 Finder 询问该文件的容器:

tell application "Finder"
    tell application "Finder" to make new Finder window
    set file_path to (path to me)
    set target of Finder window 1 to file_path's container
end tell

【讨论】:

    【解决方案2】:

    我知道的最短方法是:

    tell application "Finder" to open ((path to me as text) & "::")
    

    编辑您的脚本会呈现以下内容:

    tell application "Finder"
        make new Finder window -- There is no need for an your second tell statement
        set file_path to (path to me as text) & "::" -- Goes up one directory
        set target of Finder window 1 to file_path
    end tell
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-04
      • 2023-03-13
      • 1970-01-01
      • 2014-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      相关资源
      最近更新 更多