获取脚本位置的父文件夹的路径:Applescript

西蒙

背景:我正在尝试编写一个简单的applescript应用程序,它将启动一个tcl应用程序,但是我陷入了脚本的第一部分。

我需要获取applescript路径的父文件夹。当我运行此代码时:

set LauncherPath to path to me
set ParentPath to container of LauncherPath

...我得到这个错误:

error "Can’t get container of alias \"Macintosh HD:Users:simon:Downloads:folder with spaces:CrossFire-master:CrossFire Launcher for Mac.app:\"." number -1728 from container of alias "Macintosh HD:Users:simon:Downloads:folder with spaces:CrossFire-master:CrossFire Launcher for Mac.app:"

阅读此答案后,我尝试了以下方法:

set LauncherPath to path to me
set RealLauncherPath to first item of LauncherPath
set ParentPath to container of RealLauncherPath

...但是我得到了这个错误:

error "Can’t get item 1 of alias \"Macintosh HD:Users:simon:Downloads:folder with spaces:CrossFire-master:CrossFire Launcher for Mac.app:\"." number -1728 from item 1 of alias "Macintosh HD:Users:simon:Downloads:folder with spaces:CrossFire-master:CrossFire Launcher for Mac.app:"

任何帮助或想法,不胜感激。提前致谢!

PS一旦我解决了以上问题,完整的脚本将如下所示:

set LauncherPath to path to me
set RealLauncherPath to first item of LauncherPath
set ParentPath to container of RealLauncherPath
set UnixPath to POSIX path of ParentPath
set launcherCrossFire to "/usr/local/bin/wish " & UnixPath & "/CrossFire.tcl > /dev/null &" -- creat command to launch CrossFire
do shell script launcherCrossFire

更新:这是包含以下答案的工作脚本:

set UnixPath to POSIX path of ((path to me as text) & "::") --get path to parent folder
set LaunchCrossFire to "/usr/local/bin/wish '" & UnixPath & "CrossFire.tcl' > /dev/null 2>&1 &" -- creat command to launch CrossFire
do shell script LaunchCrossFire -- run command
阿达兹酮

尝试:

set UnixPath to POSIX path of ((path to me as text) & "::")

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Applescript获取关闭文件夹的路径

从 C++ 中父文件夹的父文件夹中获取文件位置

Bash脚本:从脚本文件夹而不是从运行它的位置引用文件夹路径

如何从路径获取父文件夹名称

从脚本获取virtualenv的bin文件夹路径

批处理脚本以在子文件夹中查找文件夹并获取文件夹路径

朱莉娅:在相对于脚本位置的位置中创建一个新的文件夹和文件

父文件夹脚本FileNotFoundError

使用C#获取解决方案文件的父文件夹的路径

Applescript:从Shell脚本中获取编号文件夹的列表,并确定最大值

从文件夹获取文件路径

运行WinSCP脚本,该脚本位于与winscp.com不同的文件夹中

使用 VBA,如何从路径字符串中获取直接父文件夹名称?

尝试在Google Apps脚本中获取文件的文件夹路径

如何使用Apple脚本获取文件夹中最新创建的文件的路径?

获取路径中的每个文件夹

如何获取内部文件夹的路径?

使用zenity获取文件夹的路径

从路径获取文件夹名称

获取当前文件夹路径

获取特定文件夹的MediaStore路径

在Applescript的文件路径中获取所有文件夹-这样我就可以对其进行标记

Applescript Shell脚本到带空间的文件夹

AppleScript:从随机文件夹中读取主脚本

如何在JavaScript for Automation中获取当前脚本文件夹的POSIX路径?

通过bash脚本获取Android Studio项目的构建文件夹路径

使用 pyinstaller 编译后获取脚本错误的文件夹路径

如何使用CMD从文件路径获取文件夹路径

循环浏览子文件夹中所有级别的文件(不包括父文件夹),获取它们的部分路径和名称