AppleScript相对于脚本位置的路径 [英] AppleScript path relative to script location

查看:257
本文介绍了AppleScript相对于脚本位置的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to launch a Finder window of a folder that's in the same directory as my script. When I run the code below, it launches a blank Finder window set to the path of the script not to the folder.

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

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

How can I get the path to the folder of the script, not the script?

推荐答案

您已经关闭.您不需要文件的文本版本,只需要文件本身,然后可以向Finder询问该文件的容器:

You were close. You do not need the text version of the file, you only need the file itself, then you can ask Finder for that file's container:

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

这篇关于AppleScript相对于脚本位置的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆