获取applescript文件的父目录的名称

时间:2019-05-12 19:10:55

标签: applescript

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

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

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

我尝试过

#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <semaphore.h>
#define THREADS 4

void *
routine1(void *x)
{
#if 0
    int result = 2;
#else
    long result = 2;
#endif

    pthread_exit((void *) result);
}

int
main()
{
    int sum = 0;
#if 0
    int retval = 0;
#else
    void *retval;
#endif
    pthread_t threads[THREADS];

#if 0
    for (int i = 0; i < THREADS; i++)
        pthread_create(&threads[i], NULL, routine1, (void *) i);
#else
    for (long i = 0; i < THREADS; i++)
        pthread_create(&threads[i], NULL, routine1, (void *) i);
#endif

    for (int i = 0; i < THREADS; i++) {
        pthread_join(threads[i], &retval);
#if 0
        sum += retval;
#else
        sum += (long) retval;
#endif
    }

    printf("%d\n", sum);

    return 0;

}

以及基于搜索结果的其他变化形式,但我总是会出错

  

无法获取POSIX路径。

我要去哪里错了? 谢谢

1 个答案:

答案 0 :(得分:2)

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)
相关问题