2015-06-22 23 views
0

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

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 

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

+0

你不是已经问过同样的? http://stackoverflow.com/questions/30789060/play-sound-with-applescript-using-afplay-and-relative-file-path –

回答

1

你就近了。你并不需要的文件的文本版本,你只需要在文件本身,那么你可以要求查找该文件的容器:

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 
1

我知道要做到这一点,最简单的办法是:

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