【问题标题】:Get the name of the parent directory of an applescript file获取一个applescript文件的父目录名
【发布时间】:2019-09-29 20:07:43
【问题描述】:

我正在制作一个小脚本,需要使用脚本本身的父目录名称(.scpt 文件)作为变量。

例如,脚本位于 /Users/spongebob/MyProject/myscript.scpt

我需要将名为 myprojectdir 的变量设置为 MyProject。

我试过了

set myprojectdir to parent of POSIX path of me

以及基于搜索结果的其他变体,但我总是以错误告终

无法获取 POSIX 路径。

我哪里错了? 谢谢

【问题讨论】:

    标签: applescript


    【解决方案1】:

    AppleScript 本身不知道。

    你要问System Events

    tell application "System Events" to set myprojectdir to name of container of (path to me)
    

    Finder

    tell application "Finder" to set myprojectdir to name of parent of (path to me)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-04
      • 2012-01-02
      • 1970-01-01
      • 2017-04-03
      相关资源
      最近更新 更多