AppleScript 相对于脚本位置的路径 [英] AppleScript path relative to script location
本文介绍了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屋!
查看全文