如何获取文件容器文件夹的路径?

时间:2019-09-26 07:37:16

标签: applescript

我想将文件包含文件夹的路径传递给命令make new file at path。我知道如何获取当前打开的文件的路径(使用tell application "TexShop" to set thePath to get path of document 1),但是我不知道如何获取包含文件夹的路径。

我尝试使用container of,如下所示:

tell application "TeXShop" set thePath to get container of path of document 1 end tell

但是我得到这个错误: TeXShop got an error: Can’t make container of path of document 1 into type reference.

是因为虽然在应用程序查找器中允许使用容器命令,但不适用于应用程序TeXShop?

1 个答案:

答案 0 :(得分:0)

下面的AppleScript代码将获取最前端应用程序中最前端文档的路径以及其包含文件夹的路径。这还将在包含文件夹中创建新文件。

(* The Delay Command  Gives You Time To Bring The Desired App To The Front
    Mainly For Use While Testing This Code In Script Editor.app *)

delay 5 -- Can Be Removed If Not Needed

tell application (path to frontmost application as text) to ¬
    set documentPath to (get path of document 1) as POSIX file as alias

tell application "Finder" to set containingFolder to container ¬
    of documentPath as alias

tell application "Finder" to make new file at containingFolder