2015-06-22 46 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